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 URL validation by preserving percent-encoded characters #9326

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

kidneyweakx
Copy link
Contributor

@kidneyweakx kidneyweakx commented Sep 12, 2024

This issue where the @braintree/sanitize-url package automatically decodes certain percent-encoded characters (e.g., %E5%BD%93%E5%89%8D into 当前). This causes the sanitized URL to differ from the original, which can result in false validation failures for URLs containing encoded Unicode characters.

To resolve this:

  • Updated the isValidURL function to use encodeURI, ensuring that percent-encoded characters are properly maintained.
  • The function now checks both the original and encoded sanitized URLs, improving validation accuracy.

This fix ensures that URLs with percent-encoded Unicode characters are considered valid if they match either the original or the encoded version of the sanitized URL.

Test Cases:

  • Verified that both valid and invalid URLs are correctly handled after this update.

Before
Before
After
After

Let me know if you need any further changes!

Copy link

codesandbox-ci bot commented Sep 12, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1ef9264:

Sandbox Source
@keystone-6/sandbox Configuration

@dcousens dcousens added the 🐛 bug Unresolved bug label Sep 13, 2024
@dcousens
Copy link
Member

@kidneyweakx can you please add a changeset?

@dcousens dcousens self-assigned this Sep 23, 2024
@kidneyweakx
Copy link
Contributor Author

@kidneyweakx can you please add a changeset?

Added.

@dcousens dcousens merged commit 8cb70c9 into keystonejs:main Sep 24, 2024
43 of 44 checks passed
@kidneyweakx kidneyweakx deleted the fix/url-encoding-sanitization branch September 24, 2024 13:51
@dcousens dcousens mentioned this pull request Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unresolved bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants