geraintluff / uri-templates

JavaScript utility for RFC 6570: URI Templates
138 stars 21 forks source link

Fix for notReallyPercentEncode #24

Open enriched opened 6 years ago

enriched commented 6 years ago

notReallyPercentEncode was ignoring double encoded things that ended with a letter.

jwalton commented 6 years ago

Why not /%25[0-9a-fA-F][0-9a-fA-F]/g? What is this doing exactly? :P

enriched commented 6 years ago

This function is trying to undo percent encoded stuff that got percent encoded again. So the regex is meant to match things that are are percent encoded (start with the % character) followed by the hexadecimal value for percent (25), followed by a hexadecimal ascii character [0-9][0-9a-fA-F]. I am not sure if it makes a difference if you allow [0-9a-fA-F] on the first character, but the [0-9] should match a character that has been encoded.

It would probably be even better to only match the hexadecimal of characters that get encoded.