Skip to content

Instantly share code, notes, and snippets.

@fazlurr
Created July 3, 2019 02:16
Show Gist options
  • Save fazlurr/c1842aafa59f46ffca0a74c0c850128c to your computer and use it in GitHub Desktop.
Save fazlurr/c1842aafa59f46ffca0a74c0c850128c to your computer and use it in GitHub Desktop.
/**
* Decode URI Component safe to use with single %
*
* @param {string} s String to Decode
* @return {string} Decoded Result
*
* @see https://stackoverflow.com/a/54310080/5627904
*/
export const decodeURIComponentSafe = (s) => {
if (!s) return s;
return decodeURIComponent(s.replace(/%(?![0-9][0-9a-fA-F]+)/g, '%25'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment