-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat: prevent special characters from url #1266
Changes from 1 commit
79ce508
4a42549
67a3d0a
db1cd5f
f2c20b5
8e9b26d
461dd69
eb64d7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -67,6 +67,13 @@ | |||||||||||||
*/ | ||||||||||||||
protected isPagePersisted = false; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Flag to know if the query from the url has special characters. | ||||||||||||||
* | ||||||||||||||
* @internal | ||||||||||||||
*/ | ||||||||||||||
protected hasSpecialKeys = false; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Computed to know which params we must get from URL. It gets the params names from the initial | ||||||||||||||
* state, to get all default params names, and also from the `$attrs` to get the extra params | ||||||||||||||
|
@@ -156,7 +163,10 @@ | |||||||||||||
protected emitEvents(): void { | ||||||||||||||
const { all, extra } = this.parseUrlParams(); | ||||||||||||||
const metadata = this.createWireMetadata(); | ||||||||||||||
this.$x.emit('ParamsLoadedFromUrl', all, metadata); | ||||||||||||||
this.preventSpecialKey(all.query); | ||||||||||||||
if (!this.hasSpecialKeys) { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
this.$x.emit('ParamsLoadedFromUrl', all, metadata); | ||||||||||||||
} | ||||||||||||||
this.$x.emit('ExtraParamsLoadedFromUrl', extra, metadata); | ||||||||||||||
// TODO: Move this logic from here. | ||||||||||||||
if (all.query) { | ||||||||||||||
|
@@ -165,6 +175,18 @@ | |||||||||||||
this.urlLoaded = true; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Prevents the user from either typing or pasting special characters in the url query. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say:
Suggested change
|
||||||||||||||
* | ||||||||||||||
* @internal | ||||||||||||||
* @param query - Query from the url that will be checked for special characters. | ||||||||||||||
*/ | ||||||||||||||
protected preventSpecialKey(query: string): void { | ||||||||||||||
if (/[<>]/.test(query ?? '')) { | ||||||||||||||
this.hasSpecialKeys = true; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why storing this value in
|
||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Creates the wire metadata to include in every emitted {@link XEvent}. | ||||||||||||||
* | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, I think I like the approach, but why are we preventing to emit the event if we have special keys instead of removing them, and send send it without them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you prefer to remove the special keys instead of the whole query? I mean, if you have this query
round <hola> shirt
, it would be transformed intoround shirt
and sent into theParamsLoadedFromUrl
event.I use this approach because, in the task description, I understood that we have to clean/remove the whole query. But for me makes more sense to remove only the special characters and the string inside them.