# Decode an URL string

### Challenge

I think everyone of us heard of URL encoding mechanism - it's basically everywhere.

Given an URLEncoded string on stdin, decode it, and output the decoded form to stdout.

The encoding is very simple, + or %20 is representing space. Every percent followed by two hex digits (uppercase or lowercase) has to be replaced with ASCII character code of this number.

Related, but it's the other way round

### Example

100%25+working
=>
100% working

%24+%26+%3C+%3E+%3F+%3B+%23+%3A+%3D+%2C+%22+%27+%7E+%2B+%25
=>
$& < > ? ; # : = , " ' ~ + % %414243 => A4243  Test case that fails: %24%XY+%%% ^~~~~~~ =>$


### Rules

• Loopholes are forbidden.
• If your programming language has built-in function to decode the URL, using it (the function) is forbidden.
• Assume ASCII character set. No Unicode and all that stuff.
• This is a code-golf, so the answer with the fewest bytes used to accomplish the task wins.
• Your program has to decode until EOF or an error (eg. percent without valid hex digits - %xy) is spotted (you can safetly terminate).
• If anything is unclear, please let me know down in the comments.
• * has to decode until * ... this feels like it assumes a specific method of solving the problem, i.e that you will decode left to right. – Expired Data Aug 2 '19 at 9:58
• The whole validation part of this is just additional to the challenge. I don't see why it's added on, it makes it two separate challenges. i.e URL decode a string (the named challenge) and validate whether a string is a valid URL encoded string (which is a different challenge imo) – Expired Data Aug 2 '19 at 10:05
• Who says I'm going to read it right to left, what if I split the input by %, and then do my work. What if I read right to left and determine if I see two characters and then a percent and then do work on it etc. etc. just because you aren't capable of understanding how a problem may be solved doesn't make it the impossible. – Expired Data Aug 2 '19 at 10:09
• (also, you could change the name of the challenge to "Decode the URL as far as possible" or similar - I don't think it's a bad challenge at all if you set the correct expectations from the start) – Sanchises Aug 2 '19 at 10:50
• Does it absolutely need to be stdin, rather than default IO rules? Also, agreed the required input validation makes it feel like a chameleon challenge... on some platforms the code to do that may be longer than the actual challenge. – 640KB Aug 2 '19 at 20:26

# 05AB1E, 41 30 bytes

'+ð:Δć©'%Qi2ôćuDHç©ÇhÊiq}J}®?


-11 bytes thanks to @Grimy.

Explanation:

'+ð:                  '# Replace all "+" in the (implicit) input with spaces
Δ                      # Loop until the result no longer changes:
ć                     #  Extract head; pop and push remainder-string and first character
©                    #  Store the character in variable ® (without popping)
'%Qi               '#  If this character is a "%":
2ô              #   Split the remainder-string into parts of size 2
#    i.e. "abcde" → ["ab","cd","e"]
u            #   Convert it to uppercase
D           #   Duplicate it
H          #   Convert it from hexadecimal to integer
#   (NOTE: even if it isn't a valid hexadecimal string,
#    it will still result in an integer regardless)
ç         #   And then from integer to ASCII-character with this codepoint
©        #   Replace variable ® with this (without popping)
Çh     #   Reverse process: ASCII-character → integer → hexadecimal string
Êi   #   If both are NOT equal (so it initially was invalid hexadecimal):
q  #    Stop the program
}J  #   And join the list of 2-char strings back together
}®?              #  And then print ®$$$$ without newline

• Fails on lowercase (challenge explicitly says lowercase hex has to be handled too). – Grimmy Aug 2 '19 at 13:02
• @Grimy Straight-forward fix with +3 bytes for now (adding Dl«). Thanks for reporting. I did check if H would convert lowercase or mixed case characters correctly, but forgot about my å check.. – Kevin Cruijssen Aug 2 '19 at 13:09
• 36 – Grimmy Aug 2 '19 at 13:41
• 30 – Grimmy Aug 2 '19 at 13:47
• @Grimy Nice, thanks. :) – Kevin Cruijssen Aug 2 '19 at 15:39

# Gema, 45 characters

+=
%<X2>=@int-char{@radix{16;10;$1}} %=@fail  Insensitive on hexadecimal case. Sample run: bash-5.0$ gema '+= ;%<X2>=@int-char{@radix{16;10;$1}};%=@fail' <<<$'100%25+working\n%24+%26+%3C+%3E+%3F+%3B+%23+%3A+%3D+%2C+%22+%27+%7E+%2B+%25\n%414243\n%24+%XY+%%%'
100% working
$& < > ? ; # : = , " ' ~ + % A4243$


Try it online!

# Stax, 29 bytes

í☼∩ò☺µ◘Γπ╓l▄╓█₧ß:♦+ÇP¢Y╚↑░ºHÑ


Run and debug it

It's mostly regex.