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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kidneyweakx
Copy link

@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

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 6d64294:

Sandbox Source
@keystone-6/sandbox Configuration

@dcousens dcousens added the 🐛 bug Unresolved bug label Sep 13, 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