Skip to content

Instantly share code, notes, and snippets.

@moimikey
Created March 28, 2014 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moimikey/8f4f61bd4e7b3018b7b3 to your computer and use it in GitHub Desktop.
Save moimikey/8f4f61bd4e7b3018b7b3 to your computer and use it in GitHub Desktop.
Util.encodeRFC5987 = (string) ->
encodeURIComponent(string)
# Note that although RFC3986 reserves "!", RFC5987 does not,
# so we do not need to escape it
.replace(/['()]/g, escape)
.replace(/\*/g, '%2A')
# The following are not required for percent-encoding per RFC5987,
# so we can allow for a little better readability over the wire: |`^
.replace(/%(?:7C|60|5E)/g, unescape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment