From 838d0788ba5eb93913127c5e9338343da0b0c4d0 Mon Sep 17 00:00:00 2001 From: Tom Scavo Date: Sat, 14 Jan 2017 16:10:28 -0500 Subject: [PATCH] Refactor percent_decode as inverse of percent_encode --- lib/http_tools.sh | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/http_tools.sh b/lib/http_tools.sh index c537517..92fc74e 100755 --- a/lib/http_tools.sh +++ b/lib/http_tools.sh @@ -491,8 +491,8 @@ get_header_value () { } ####################################################################### -# This function percent-encodes all characters except the "Unreserved -# Characters" defined in section 2.3 of RFC 3986. +# This function percent-encodes all characters in its string argument +# except the "Unreserved Characters" defined in section 2.3 of RFC 3986. # # See: https://gist.github.com/cdown/1163649 # https://en.wikipedia.org/wiki/Percent-encoding @@ -523,7 +523,9 @@ percent_encode () { } ####################################################################### -# This function percent-decodes all percent-encoded characters. +# This function is the inverse of the percent_encode function, that +# is, it percent-decodes all percent-encoded characters in its string +# argument. ####################################################################### percent_decode () { # percent_decode @@ -534,15 +536,7 @@ percent_decode () { return 2 fi - local encoded_string - - # the percent_encode function doesn't convert spaces to - # plus signs (+) but the input string to the percent_decode - # function may have been encoded in some other manner so we - # first decode plus signs (+) into spaces - encoded_string="${1//+/ }" - - printf '%b' "${encoded_string//%/\\x}" + printf '%b' "${1//%/\\x}" } # DEPRECATED: Use percent_encode and percent_decode instead.