Skip to content

Commit

Permalink
chore: new approach using sanitize util
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar committed Sep 5, 2023
1 parent 461dd69 commit eb64d7f
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions packages/x-components/src/x-modules/url/components/url-handler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { FeatureLocation } from '../../../types/origin';
import { UrlParams } from '../../../types/url-params';
import { isArrayEmpty } from '../../../utils/array';
import { sanitize } from '../../../utils/index';
import { WireMetadata } from '../../../wiring/wiring.types';
import { SnippetConfig } from '../../../x-installer/api/api.types';
import { initialUrlState } from '../store/initial-state';
Expand Down Expand Up @@ -165,27 +166,6 @@
this.urlLoaded = true;
}
/**
* Detects if the user typing or pasting special/forbidden characters in some URL param and removes them.
*
* @internal
* @param urlValue - Param from the url that will be checked for special characters.
* @returns Param without special characters.
*/
protected removeSpecialKeys(urlValue: string): string {
if (/[<>]/.test(urlValue ?? '')) {
let value = urlValue.replace(/<.*>/g, '');
if (!/</.test(value ?? '')) {
value = value.replace(/.*>/g, '');
} else if (!/>/.test(value ?? '')) {
value = value.replace(/<.*/g, '');
}
return value;
} else {
return urlValue;
}
}
/**
* Creates the wire metadata to include in every emitted {@link XEvent}.
*
Expand Down Expand Up @@ -277,11 +257,11 @@
if (urlSearchParams.has(urlKey)) {
if (name in initialUrlState) {
let urlValue = urlSearchParams.getAll(urlKey);
urlValue[0] = this.removeSpecialKeys(urlValue[0]);
urlValue[0] = sanitize(urlValue[0]);
params.all[name] = this.parseUrlParam(name, urlValue);
} else {
let urlValueExtra = urlSearchParams.get(urlKey);
urlValueExtra = this.removeSpecialKeys(urlValueExtra!);
urlValueExtra = sanitize(urlValueExtra!);
params.all[name] = params.extra[name] = urlValueExtra;
}
}
Expand Down

0 comments on commit eb64d7f

Please sign in to comment.