-
Notifications
You must be signed in to change notification settings - Fork 213
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/Validate URLTemplates before tracking #448
Conversation
8037fd8
to
0ecb10b
Compare
src/util/util.js
Outdated
* or | ||
* - be protocol-relative urls | ||
* | ||
* @param {String|String[]|Object[]} URLTemplates - A string|string[]|object[] of url templates. |
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.
* @param {String|String[]|Object[]} URLTemplates - A string|string[]|object[] of url templates. | |
* @param {Array} URLTemplates - An Array of url templates. |
It should be only this no? As we are expecting an array all the time, and also this is the input value from trackURLs
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.
Good one. I needed to check after the urls that are not in an array such as survey. As far as I know, this is the only case, and it's not called using trackURLs. Update inc.
src/util/util.js
Outdated
} | ||
|
||
function isValidUrl(url) { | ||
return (url?.startsWith('http://') || url?.startsWith('https://') || url?.startsWith('//')); |
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.
Isn't it more performant and also more elegant with only one regex?
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.
Not sure, because this can make http url valid for https hosts, and I'm pretty bad at regex xD.
My first version used window.location but the testing can be limited if we mock the location to https://something for example.
return (url?.startsWith(window.location.protocol) || url?.startsWith('//'))
Description
Check and validate tracking urls before requesting them.
Issue
Provided tracking urls are not always valid urls
Type