cli icon indicating copy to clipboard operation
cli copied to clipboard

Invalid URL Fix: Decoding manually for some reserved characters

Open this-is-shivamsingh opened this issue 1 year ago • 0 comments

Reference PR: https://github.com/percy/cli/pull/1664

  • While testing the previous PR, we found for 11/18 reserved characters, JS neither encodes/decodes this.
  • When a user gives original characters like # : /, then we don't have an issue, but if user given an encoded value of these characters, it does get's decoded, and while encoding the % part of get encoded again
decodeURI('%23') -> output: %23
encodeURI('%23') -> output: %2523
  • To resolve this issue we are decoding these encoded characters manually.
  • General public URLs/endpoints are not like this, but if someone is using a localhost, and hosted a file(containing this encoded value) for taking a snapshot then creates an issue, when the response is 404 after modifying the URL.
  • We tested for all reserved and unreserved characters from the official Wikipedia docs(https://en.wikipedia.org/wiki/Percent-encoding) and only found these 11 characters that were causing this issue.

Changes:

  • Manually decoding some reserved characters.
  • A feature flag to disable this modification in case user encounter some issues with this.

List of all reserved characters for which decodeURI, doesn't work.

# -> %23
$ -> %24
: -> %3A
& -> %26
+ -> %2B
, -> %2C
/ -> %2F
; -> %3B
= -> %3D
? -> %3F
@ -> %40

this-is-shivamsingh avatar Jul 31 '24 19:07 this-is-shivamsingh