Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quoting and url-encoding #153

Merged
merged 6 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ export const getTimeFieldsFromUrl = () => {
const url = unhashUrl(window.location.href);

let [, fromDateString, toDateString] = url.match(timeRangeMatcher);
fromDateString = fromDateString.replace(/[']+/g, '');
fromDateString = decodeURIComponent(fromDateString.replace(/[']+/g, ''));
// convert time range to from date format in case time range is relative
const fromDateFormat = dateMath.parse(fromDateString);
toDateString = toDateString.replace(/[']+/g, '');
const toDateFormat = dateMath.parse(toDateString);
toDateString = decodeURIComponent(toDateString.replace(/[']+/g, ''));
const toDateFormat = dateMath.parse(toDateString, { roundUp: true });

const timeDuration = moment.duration(
dateMath.parse(toDateString).diff(dateMath.parse(fromDateString))
);
const timeDuration = moment.duration(toDateFormat.diff(fromDateFormat));

return {
time_from: fromDateFormat,
Expand Down Expand Up @@ -141,22 +139,23 @@ export const replaceQueryURL = (pageUrl) => {
// we unhash the url in case OpenSearch Dashboards advanced UI setting 'state:storeInSessionStorage' is turned on
const unhashedUrl = new URL(unhashUrl(pageUrl));
let queryUrl = unhashedUrl.pathname + unhashedUrl.hash;
let [, fromDateString, toDateString] = queryUrl.match(timeRangeMatcher);
fromDateString = fromDateString.replace(/[']+/g, '');
let [, fromDateStringMatch, toDateStringMatch] =
queryUrl.match(timeRangeMatcher);
fromDateString = decodeURIComponent(fromDateStringMatch.replace(/[']+/g, ''));

// convert time range to from date format in case time range is relative
const fromDateFormat = dateMath.parse(fromDateString);
toDateString = toDateString.replace(/[']+/g, '');
const toDateFormat = dateMath.parse(toDateString);
toDateString = decodeURIComponent(toDateStringMatch.replace(/[']+/g, ''));
const toDateFormat = dateMath.parse(toDateString, { roundUp: true });

// replace to and from dates with absolute date
queryUrl = queryUrl.replace(
fromDateString,
fromDateStringMatch,
"'" + fromDateFormat.toISOString() + "'"
);
queryUrl = queryUrl.replace(
toDateString + '))',
"'" + toDateFormat.toISOString() + "'))"
toDateStringMatch,
"'" + toDateFormat.toISOString() + "'"
);
return queryUrl;
};
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export function ReportDetails(props: { match?: any; setBreadcrumbs?: any; httpCl
timeRangeMatcher
);

fromDateString = fromDateString.replace(/[']+/g, '');
toDateString = toDateString.replace(/[']+/g, '');
fromDateString = fromDateString.replace(/[']+/g, '').replace('%2F','/');
toDateString = toDateString.replace(/[']+/g, '').replace('%2F','/');
kroussou marked this conversation as resolved.
Show resolved Hide resolved

let fromDateParsed = dateMath.parse(fromDateString);
let toDateParsed = dateMath.parse(toDateString);
Expand Down