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/Validate URLTemplates before tracking #448

Merged
merged 2 commits into from
Jul 26, 2023
Merged

Fix/Validate URLTemplates before tracking #448

merged 2 commits into from
Jul 26, 2023

Conversation

Lotphy
Copy link
Contributor

@Lotphy Lotphy commented Jun 12, 2023

Description

Check and validate tracking urls before requesting them.

Issue

Provided tracking urls are not always valid urls

Type

  • Breaking change
  • Enhancement
  • Fix
  • Documentation
  • Tooling

@Lotphy Lotphy force-pushed the PV-19335 branch 3 times, most recently from 8037fd8 to 0ecb10b Compare June 13, 2023 16:26
@Lotphy Lotphy changed the title PV-19335: filter URLTemplates by protocol Filter URLTemplates by protocol Jun 14, 2023
@Lotphy Lotphy changed the title Filter URLTemplates by protocol Fix/Valid URLTemplates before tracking Jun 14, 2023
@Lotphy Lotphy changed the title Fix/Valid URLTemplates before tracking Fix/Validate URLTemplates before tracking Jun 14, 2023
@Lotphy Lotphy self-assigned this Jun 16, 2023
src/util/util.js Outdated
* or
* - be protocol-relative urls
*
* @param {String|String[]|Object[]} URLTemplates - A string|string[]|object[] of url templates.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @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

Copy link
Contributor Author

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('//'));
Copy link
Contributor

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?

Copy link
Contributor Author

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('//'))

@ZacharieTFR ZacharieTFR merged commit ca0286c into master Jul 26, 2023
1 check passed
@ZacharieTFR ZacharieTFR deleted the PV-19335 branch July 26, 2023 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants