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

Detect and modify invalid URL characters #1664

Merged
merged 12 commits into from
Jul 24, 2024
Merged

Conversation

this-is-shivamsingh
Copy link
Contributor

@this-is-shivamsingh this-is-shivamsingh commented Jul 18, 2024

Jira: https://browserstack.atlassian.net/browse/PPLT-3177
Issues:

  • When the snapshot URL contains invalid characters that are not supported as a part of valid URI syntax, it causes the renderer to break due to strict checking of URLs.
  • These invalid URLs result in either parsing issues OR invalid responses like 404/ 307(redirect to with corrected URL) by browsers, which can cause resources not to get loaded in time or bad URI errors.
  • Mostly this causes Renderer Timeout as per some previously reported issues by users.

Changes:

  1. Encoding url using encodeURI, this encodes the invalid/unsupported characters with their respective encoding characters.
    Eg:
<space> -> %20
[ -> %5B
] -> %5D and so on.
  1. In case the URL is partially encoded by the user, we first decode it and then encode it, so that the already encoded character should not get encoded again, doing decodeURI first makes the URL to come in original form and then encodeURI, converts every unsupported character to there respective encoded character. This avoids encoding of already encoded characters.
  2. If the URL is valid, then decoding will not affect anything, it only decodes the already encoded character to the original character. Eg. /abc -> /abc, %20 -> <space>, %5B -> [ and so on.

Testing:

  1. Run builds with different types of valid and invalid URLs to verify where it break.
  2. Test with url’s containing # $ % !, * <space> [ ] {} etc, that are generally unsupported by browsers.

@this-is-shivamsingh this-is-shivamsingh requested a review from a team as a code owner July 18, 2024 19:41
@this-is-shivamsingh this-is-shivamsingh changed the title feat: added invalid URL detection for snapshot & network urls Detect and modify invalid URL characters Jul 18, 2024
packages/core/src/network.js Outdated Show resolved Hide resolved
packages/core/src/snapshot.js Outdated Show resolved Hide resolved
packages/core/src/utils.js Outdated Show resolved Hide resolved
@this-is-shivamsingh this-is-shivamsingh merged commit a555427 into master Jul 24, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants