URL decoding: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Raku}}: use 'xdigit', better documented)
m (syntax highlighting fixup automation)
Line 13:
 
=={{header|11l}}==
<langsyntaxhighlight lang="11l">F url_decode(s)
V r = ‘’
V i = 0
Line 30:
 
print(url_decode(‘http%3A%2F%2Ffoo%20bar%2F’))
print(url_decode(‘https://ru.wikipedia.org/wiki/%D0%A2%D1%80%D0%B0%D0%BD%D1%81%D0%BF%D0%B0%D0%B9%D0%BB%D0%B5%D1%80’))</langsyntaxhighlight>
 
{{out}}
Line 40:
=={{header|ABAP}}==
 
<langsyntaxhighlight ABAPlang="abap">REPORT Z_DECODE_URL.
 
DATA: lv_encoded_url TYPE string VALUE 'http%3A%2F%2Ffoo%20bar%2F',
Line 51:
UNESCAPED = lv_decoded_url.
 
WRITE: 'Encoded URL: ', lv_encoded_url, /, 'Decoded URL: ', lv_decoded_url.</langsyntaxhighlight>
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC Append(CHAR ARRAY s CHAR c)
s(0)==+1
s(s(0))=c
Line 118:
Test("http%3A%2F%2Ffoo%20bar%2F")
Test("http%3A%2F%2Ffoo+bar%2F*_-.html")
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/URL_decoding.png Screenshot from Atari 8-bit computer]
Line 131:
=={{header|Ada}}==
{{libheader|AWS}}
<langsyntaxhighlight Adalang="ada">with AWS.URL;
with Ada.Text_IO; use Ada.Text_IO;
procedure Decode is
Line 138:
Put_Line (AWS.URL.Decode (Encoded));
end Decode;
</syntaxhighlight>
</lang>
 
Without external libraries:
 
<langsyntaxhighlight Adalang="ada">package URL is
function Decode (URL : in String) return String;
end URL;</langsyntaxhighlight>
 
<langsyntaxhighlight Adalang="ada">package body URL is
function Decode (URL : in String) return String is
Buffer : String (1 .. URL'Length);
Line 173:
return Buffer (1 .. Filled);
end Decode;
end URL;</langsyntaxhighlight>
 
<langsyntaxhighlight Adalang="ada">with Ada.Command_Line,
Ada.Text_IO;
 
Line 190:
end loop;
end if;
end Test_URL_Decode;</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 197:
<br>
For the second task example, this outputs the encoded UTF-8 characters, what you see depends on what you look at it with...
<langsyntaxhighlight lang="algol68"># returns c decoded as a hex digit #
PROC hex value = ( CHAR c )INT: IF c >= "0" AND c <= "9" THEN ABS c - ABS "0"
ELIF c >= "A" AND c <= "F" THEN 10 + ( ABS c - ABS "A" )
Line 232:
# test the url decode procedure #
print( ( url decode( "http%3A%2F%2Ffoo%20bar%2F" ), newline ) );
print( ( url decode( "google.com/search?q=%60Abdu%27l-Bah%C3%A1" ), newline ) )</langsyntaxhighlight>
{{out}}
<pre>
Line 240:
 
=={{header|Apex}}==
<langsyntaxhighlight lang="apex">EncodingUtil.urlDecode('http%3A%2F%2Ffoo%20bar%2F', 'UTF-8');
EncodingUtil.urlDecode('google.com/search?q=%60Abdu%27l-Bah%C3%A1', 'UTF-8');</langsyntaxhighlight>
<pre>http://foo bar/
google.com/search?q=`Abdu'l-Bahá</pre>
Line 247:
=={{header|AppleScript}}==
{{libheader|AppleScript Toolbox}}
<langsyntaxhighlight AppleScriptlang="applescript">AST URL decode "google.com/search?q=%60Abdu%27l-Bah%C3%A1"</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">print decode.url "http%3A%2F%2Ffoo%20bar%2F"
print decode.url "google.com/search?q=%60Abdu%27l-Bah%C3%A1"</langsyntaxhighlight>
 
{{out}}
Line 260:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">encURL := "http%3A%2F%2Ffoo%20bar%2F"
SetFormat, Integer, hex
Loop Parse, encURL
Line 273:
else out .= A_LoopField
MsgBox % out ; http://foo bar/
</syntaxhighlight>
</lang>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax:
awk '
Line 299:
return num + (length(s) ? 16*hex2dec(s) : 0)
} '
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 308:
OR:
 
<langsyntaxhighlight lang="awk">
LC_ALL=C
echo "http%3A%2F%2Ffoo%20bar%2F" | gawk -vRS='%[[:xdigit:]]{2}' '
RT {RT = sprintf("%c",strtonum("0x" substr(RT, 2)))}
{gsub(/+/," ");printf "%s", $0 RT}'
</syntaxhighlight>
</lang>
 
{{out}}
Line 321:
 
=={{header|BaCon}}==
<langsyntaxhighlight lang="freebasic">FUNCTION Url_Decode$(url$)
 
LOCAL result$
Line 334:
 
PRINT Url_Decode$("http%3A%2F%2Ffoo%20bar%2F")
PRINT Url_Decode$("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</langsyntaxhighlight>
{{out}}
<pre>
Line 343:
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> PRINT FNurldecode("http%3A%2F%2Ffoo%20bar%2F")
END
Line 364:
IF C% >= 97 IF C% <= 122 MID$(A$,A%,1) = CHR$(C%-32)
NEXT
= A$</langsyntaxhighlight>
{{out}}
<pre>
Line 371:
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat">( ( decode
= decoded hexcode notencoded
. :?decoded
Line 381:
)
& out$(decode$http%3A%2F%2Ffoo%20bar%2F)
);</langsyntaxhighlight>
{{out}}
<pre>http://foo bar/</pre>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
 
Line 425:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp}}==
 
<langsyntaxhighlight lang="csharp">using System;
 
namespace URLEncode
Line 445:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 455:
{{libheader|Poco}}
{{works with|g++}}
<langsyntaxhighlight lang="cpp">#include <string>
#include "Poco/URI.h"
#include <iostream>
Line 465:
std::cout << encoded << " is decoded: " << decoded << " !" << std::endl ;
return 0 ;
}</langsyntaxhighlight>
{{out}}
<pre>http%3A%2F%2Ffoo%20bar%2F is decoded: http://foo bar/ !</pre>
Line 476:
=={{header|Clojure}}==
 
<langsyntaxhighlight lang="clojure">(java.net.URLDecoder/decode "http%3A%2F%2Ffoo%20bar%2F")</langsyntaxhighlight>
 
=={{header|CoffeeScript}}==
 
<langsyntaxhighlight lang="coffeescript">
console.log decodeURIComponent "http%3A%2F%2Ffoo%20bar%2F?name=Foo%20Barson"
</syntaxhighlight>
</lang>
 
<syntaxhighlight lang="text">
> coffee foo.coffee
http://foo bar/?name=Foo Barson
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defun decode (string &key start)
(assert (char= (char string start) #\%))
(if (>= (length string) (+ start 3))
Line 512:
finally (return (apply #'concatenate 'string chunks))))
 
(url-decode "http%3A%2F%2Ffoo%20bar%2F")</langsyntaxhighlight>
{{out}}
<pre>"http://foo bar/"</pre>
 
=={{header|Crystal}}==
<langsyntaxhighlight lang="crystal">require "uri"
 
puts URI.decode "http%3A%2F%2Ffoo%20bar%2F"
puts URI.decode "google.com/search?q=%60Abdu%27l-Bah%C3%A1"</langsyntaxhighlight>
{{out}}
<pre>http://foo bar/
Line 526:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio, std.uri;
 
void main() {
writeln(decodeComponent("http%3A%2F%2Ffoo%20bar%2F"));
}</langsyntaxhighlight>
<pre>http://foo bar/</pre>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program URLEncoding;
 
{$APPTYPE CONSOLE}
Line 542:
begin
Writeln(TIdURI.URLDecode('http%3A%2F%2Ffoo%20bar%2F'));
end.</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">IO.inspect URI.decode("http%3A%2F%2Ffoo%20bar%2F")
IO.inspect URI.decode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</langsyntaxhighlight>
 
{{out}}
Line 563:
=={{header|F_Sharp|F#}}==
{{trans|C#}}
<langsyntaxhighlight lang="fsharp">open System
 
let decode uri = Uri.UnescapeDataString(uri)
Line 570:
let main argv =
printfn "%s" (decode "http%3A%2F%2Ffoo%20bar%2F")
0</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: io kernel urls.encoding ;
IN: rosetta-code.url-decoding
 
"http%3A%2F%2Ffoo%20bar%2F"
"google.com/search?q=%60Abdu%27l-Bah%C3%A1"
[ url-decode print ] bi@</langsyntaxhighlight>
{{out}}
<pre>
Line 587:
=={{header|Free Pascal}}==
 
<langsyntaxhighlight lang="pascal">function urlDecode(data: String): AnsiString;
var
ch: Char;
Line 612:
pos := pos +1;
end;
end;</langsyntaxhighlight>
 
 
Line 618:
{{trans|Liberty BASIC}}
{{trans|Pascal}}
<langsyntaxhighlight lang="freebasic">
Const alphanum = "0123456789abcdefghijklmnopqrstuvwxyz"
 
Line 658:
Print "URL decoding '"; url2string(URL); "'"
Sleep
</syntaxhighlight>
</lang>
 
=={{header|Frink}}==
While the default is to decode parameters as UTF-8 (which is the W3C recommendation,) the characters may have been encoded in another encoding scheme, and this can be handled correctly.
<langsyntaxhighlight lang="frink">URLDecode["google.com/search?q=%60Abdu%27l-Bah%C3%A1","UTF8"]</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 685:
fmt.Println(u)
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 693:
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">assert URLDecoder.decode('http%3A%2F%2Ffoo%20bar%2F') == 'http://foo bar/'</langsyntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight Haskelllang="haskell">import qualified Data.Char as Char
 
urlDecode :: String -> Maybe String
Line 710:
 
main :: IO ()
main = putStrLn . maybe "Bad decode" id $ urlDecode "http%3A%2F%2Ffoo%20bar%2F"</langsyntaxhighlight>
{{out}}
<pre>http://foo bar/</pre>
 
Another approach:
<langsyntaxhighlight lang="haskell">import Data.Char (chr)
import Data.List.Split (splitOn)
 
Line 727:
-- TEST ------------------------------------------------------------------------
main :: IO ()
main = putStrLn $ deCode "http%3A%2F%2Ffoo%20bar%2F"</langsyntaxhighlight>
{{Out}}
<pre>http://foo bar/</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">link hexcvt
 
procedure main()
Line 753:
else move(1)
return c
end</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 767:
Here is an implementation:
 
<langsyntaxhighlight lang="j">require'strings convert'
urldecode=: rplc&(~.,/;"_1&a."2(,:tolower)'%',.toupper hfd i.#a.)</langsyntaxhighlight>
 
Example use:
 
<langsyntaxhighlight lang="j"> urldecode 'http%3A%2F%2Ffoo%20bar%2F'
http://foo bar/</langsyntaxhighlight>
 
Note that an earlier implementation assumed the j6 implementation of <code>hfd</code> which where hexadecimal letters resulting from <code>hfd</code> were upper case. J8, in contrast, provides a lower case result from hfd. The addition of <code>toupper</code> guarantees the case insensitivity required by [http://tools.ietf.org/html/rfc3986#section-2.1 RFC 3986] regardless of which version of J you are using. As the parenthesized expression containing <code>hfd</code> is only evaluated at definition time, there's no performance penalty from the use of <code>toupper</code>.
Line 779:
Example use:
 
<langsyntaxhighlight lang="j"> urldecode 'google.com/search?q=%60Abdu%27l-Bah%C3%A1'
google.com/search?q=`Abdu'l-Bahá</langsyntaxhighlight>
 
=={{header|Java}}==
 
<langsyntaxhighlight lang="java">import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
 
Line 795:
System.out.println(normal);
}
}</langsyntaxhighlight>
 
{{out}}
Line 801:
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">decodeURIComponent("http%3A%2F%2Ffoo%20bar%2F")</langsyntaxhighlight>
 
=={{header|jq}}==
{{works with|jq|1.4}}
If your jq already has "until", then the definition given below may be omitted.
<langsyntaxhighlight lang="jq"># Emit . and stop as soon as "condition" is true.
def until(condition; next):
def u: if condition then . else (next|u) end;
Line 832:
else [ $i + 1, .[1] + $in[$i:$i+1] ]
end)
| .[1]; # answer</langsyntaxhighlight>
'''Example''':
<langsyntaxhighlight lang="jq">"http%3A%2F%2Ffoo%20bar%2F" | url_decode</langsyntaxhighlight>
{{out}}
<syntaxhighlight lang="sh">
<lang sh>
"http://foo bar/"</langsyntaxhighlight>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
using URIParser
 
Line 848:
 
println(enc, " => ", dcd)
</syntaxhighlight>
</lang>
 
{{out}}
Line 856:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.net.URLDecoder
Line 863:
val encoded = arrayOf("http%3A%2F%2Ffoo%20bar%2F", "google.com/search?q=%60Abdu%27l-Bah%C3%A1")
for (e in encoded) println(URLDecoder.decode(e, "UTF-8"))
}</langsyntaxhighlight>
 
{{out}}
Line 872:
 
=={{header|Ksh}}==
<syntaxhighlight lang="ksh">
<lang Ksh>
url_decode()
{
Line 881:
url_decode "http%3A%2F%2Ffoo%20bar%2F"
url_decode "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
</syntaxhighlight>
</lang>
 
{{out}}
Line 891:
=={{header|Lambdatalk}}==
Currently lambdatalk has no builtin primitive for decoding URLs. Let's define it using Javascript.
<langsyntaxhighlight lang="scheme">
1) define a new javascript primitive:
{script
Line 905:
 
 
</syntaxhighlight>
</lang>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">bytes('http%3A%2F%2Ffoo%20bar%2F') -> decodeurl</langsyntaxhighlight>
-> http://foo bar/
 
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
<lang lb>
dim lookUp$( 256)
 
Line 938:
next j
end function
</syntaxhighlight>
</lang>
Supplied URL 'http%3A%2F%2Ffoo%20bar%2F'
As string 'http://foo bar/'
 
=={{header|Lingo}}==
<langsyntaxhighlight Lingolang="lingo">----------------------------------------
-- URL decodes a string
-- @param {string} str
Line 966:
ba.position = 1
return ba.readRawString(ba.length)
end</langsyntaxhighlight>
<langsyntaxhighlight Lingolang="lingo">put urldecode("http%3A%2F%2Ffoo%20bar%2F")
put urldecode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</langsyntaxhighlight>
{{Out}}
<pre>
Line 976:
 
=={{header|LiveCode}}==
<langsyntaxhighlight LiveCodelang="livecode">put urlDecode("http%3A%2F%2Ffoo%20bar%2F") & cr & \
urlDecode("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</langsyntaxhighlight>Results<syntaxhighlight lang="text">http://foo bar/
google.com/search?q=`Abdu'l-Bah√°</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">function decodeChar(hex)
return string.char(tonumber(hex,16))
end
Line 991:
 
-- will print "http://foo bar/"
print(decodeString("http%3A%2F%2Ffoo%20bar%2F"))</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Line 1,001:
 
b$=chr$(a$) revert bytes to words adding zeroes after each character
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Function decodeUrl$(a$) {
Line 1,027:
}
CheckIt
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">StringTools:-Decode("http%3A%2F%2Ffoo%20bar%2F", encoding=percent);</langsyntaxhighlight>
 
{{Out}}
Line 1,036:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang="mathematica">URLDecoding[url_] :=
StringReplace[url, "%" ~~ x_ ~~ y_ :> FromDigits[x ~~ y, 16]] //.
StringExpression[x___, Longest[n__Integer], y___] :>
StringExpression[x, FromCharacterCode[{n}, "UTF8"], y]</langsyntaxhighlight>
Example use:
<langsyntaxhighlight lang="mathematica">URLDecoding["http%3A%2F%2Ffoo%20bar%2F"]</langsyntaxhighlight>
{{out}}
<pre>http://foo bar/</pre>
Line 1,061:
 
=={{header|MATLAB}} / {{header|Octave}}==
<langsyntaxhighlight MATLABlang="matlab">function u = urldecoding(s)
u = '';
k = 1;
Line 1,073:
end
end
end</langsyntaxhighlight>
Usage:
<pre>octave:3> urldecoding('http%3A%2F%2Ffoo%20bar%2F')
Line 1,079:
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
Line 1,122:
 
return decoded
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,137:
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">;; universal decoder, works for ASCII and UTF-8
;; (source http://www.newlisp.org/index.cgi?page=Code_Snippets)
(define (url-decode url (opt nil))
Line 1,143:
(replace "%([0-9a-f][0-9a-f])" url (pack "b" (int $1 0 16)) 1))
 
(url-decode "http%3A%2F%2Ffoo%20bar%2F")</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import cgi
 
echo decodeUrl("http%3A%2F%2Ffoo%20bar%2F")</langsyntaxhighlight>
 
{{out}}
Line 1,155:
=={{header|Oberon-2}}==
{{works with|oo2c}}
<langsyntaxhighlight lang="oberon2">
MODULE URLDecoding;
IMPORT
Line 1,164:
Out.String(URI.Unescape("google.com/search?q=%60Abdu%27l-Bah%C3%A1"));Out.Ln;
END URLDecoding.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,172:
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
class UrlDecode {
function : Main(args : String[]) ~ Nil {
Line 1,178:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Objective-C}}==
<langsyntaxhighlight lang="objc">NSString *encoded = @"http%3A%2F%2Ffoo%20bar%2F";
NSString *normal = [encoded stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", normal);</langsyntaxhighlight>
{{works with|Mac OS X|10.9+}}{{works with|iOS|7+}}
<langsyntaxhighlight lang="objc">NSString *encoded = @"http%3A%2F%2Ffoo%20bar%2F";
NSString *normal = [encoded stringByRemovingPercentEncoding];
NSLog(@"%@", normal);</langsyntaxhighlight>
 
=={{header|OCaml}}==
Line 1,193:
Using the library [http://projects.camlcity.org/projects/ocamlnet.html ocamlnet] from the interactive loop:
 
<langsyntaxhighlight lang="ocaml">$ ocaml
# #use "topfind";;
# #require "netstring";;
 
# Netencoding.Url.decode "http%3A%2F%2Ffoo%20bar%2F" ;;
- : string = "http://foo bar/"</langsyntaxhighlight>
 
=={{header|ooRexx}}==
While the implementation shown for [[#REXX|Rexx]] will also work with ooRexx, this version uses ooRexx syntax to invoke the built-in functions.
<langsyntaxhighlight ooRexxlang="oorexx">/* Rexx */
X = 0
url. = ''
Line 1,241:
End e_
 
Return decoded</langsyntaxhighlight>
 
{{out}}
Line 1,257:
=={{header|Perl}}==
 
<langsyntaxhighlight Perllang="perl">sub urldecode {
my $s = shift;
$s =~ tr/\+/ /;
Line 1,265:
 
print urldecode('http%3A%2F%2Ffoo+bar%2F')."\n";
</syntaxhighlight>
</lang>
 
<langsyntaxhighlight Perllang="perl">#!/usr/bin/perl -w
use strict ;
use URI::Escape ;
Line 1,273:
my $encoded = "http%3A%2F%2Ffoo%20bar%2F" ;
my $unencoded = uri_unescape( $encoded ) ;
print "The unencoded string is $unencoded !\n" ;</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\decode_url.exw
Line 1,313:
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{Out}}
<pre>
Line 1,321:
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
$encoded = "http%3A%2F%2Ffoo%20bar%2F";
$unencoded = rawurldecode($encoded);
echo "The unencoded string is $unencoded !\n";
?></langsyntaxhighlight>
 
=={{header|PicoLisp}}==
Line 1,332:
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">
<lang Pike>
void main()
{
Line 1,346:
}
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,354:
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
[System.Web.HttpUtility]::UrlDecode("http%3A%2F%2Ffoo%20bar%2F")
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,363:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">URL$ = URLDecoder("http%3A%2F%2Ffoo%20bar%2F")
 
Debug URL$ ; http://foo bar/</langsyntaxhighlight>
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
#Python 2.X
import urllib
Line 1,375:
from urllib.parse import unquote
print(unquote('http%3A%2F%2Ffoo%20bar%2F'))
</syntaxhighlight>
</lang>
 
=={{header|R}}==
 
<langsyntaxhighlight Rlang="r">URLdecode("http%3A%2F%2Ffoo%20bar%2F")</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">
#lang racket
(require net/uri-codec)
(uri-decode "http%3A%2F%2Ffoo%20bar%2F")
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my @urls = < http%3A%2F%2Ffoo%20bar%2F
google.com/search?q=%60Abdu%27l-Bah%C3%A1 >;
 
Line 1,397:
/ [ '%' ( <xdigit> ** 2 ) ]+ / ,
{ Blob.new((:16(~$_) for $0)).decode }
) for @urls;</langsyntaxhighlight>
{{out}}
<pre>http://foo bar/
Line 1,404:
=={{header|Red}}==
 
<langsyntaxhighlight lang="rebol">>> dehex "http%3A%2F%2Ffoo%20bar%2F"
== "http://foo bar/"
>> dehex "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
== "google.com/search?q=`Abdu'l-Bahá"</langsyntaxhighlight>
 
=={{header|Retro}}==
This is provided by the '''casket''' library (used for web app development).
 
<langsyntaxhighlight Retrolang="retro">create buffer 32000 allot
 
{{
Line 1,427:
}}
 
"http%3A%2F%2Ffoo%20bar%2F" decode buffer puts</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 1,433:
{{Trans|ooRexx}}
Tested with the ooRexx and Regina interpreters.
<langsyntaxhighlight REXXlang="rexx">/* Rexx */
 
Do
Line 1,481:
End
Exit
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,497:
===version 2===
This REXX version is identical to version 1, but with superfluous and dead code removed.
<langsyntaxhighlight REXXlang="rexx">/*REXX program converts a URL─encoded string ──► its original unencoded form. */
url.1='http%3A%2F%2Ffoo%20bar%2F'
url.2='mailto%3A%22Ivan%20Aim%22%20%3Civan%2Eaim%40email%2Ecom%3E'
Line 1,525:
end /*while*/
 
return decoded</langsyntaxhighlight>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}}
 
===version 3===
This REXX version is a shorter version of version 2.
<langsyntaxhighlight REXXlang="rexx">/*REXX program converts & displays a URL─encoded string ──► its original unencoded form.*/
url. =
url.1='http%3A%2F%2Ffoo%20bar%2F'
Line 1,551:
else URL= URL'%'code
end /*until*/
return URL</langsyntaxhighlight>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}}
 
Line 1,557:
Use any one of <code>CGI.unescape</code> or <code>URI.decode_www_form_component</code>. These methods also convert "+" to " ".
 
<langsyntaxhighlight lang="ruby">require 'cgi'
puts CGI.unescape("http%3A%2F%2Ffoo%20bar%2F")
# => "http://foo bar/"</langsyntaxhighlight>
 
{{works with|Ruby|1.9.2}}
<langsyntaxhighlight lang="ruby">require 'uri'
puts URI.decode_www_form_component("http%3A%2F%2Ffoo%20bar%2F")
# => "http://foo bar/"</langsyntaxhighlight>
 
<code>URI.unescape</code> (alias <code>URI.unencode</code>) still works. <code>URI.unescape</code> is obsolete since Ruby 1.9.2 because of problems with its sibling <code>URI.escape</code>.
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">const INPUT1: &str = "http%3A%2F%2Ffoo%20bar%2F";
const INPUT2: &str = "google.com/search?q=%60Abdu%27l-Bah%C3%A1";
 
Line 1,604:
println!("{}", decode(INPUT1));
println!("{}", decode(INPUT2));
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,612:
 
=={{header|Scala}}==
{{libheader|Scala}}<langsyntaxhighlight lang="scala">import java.net.{URLDecoder, URLEncoder}
import scala.compat.Platform.currentTime
 
Line 1,627:
 
println(s"Successfully completed without errors. [total ${currentTime - executionStart} ms]")
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
Line 1,638:
Both functions return byte sequences.
To decode Unicode characters it is necessary to convert them from UTF-8 with ''utf8ToStri'' afterwards.
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "encoding.s7i";
 
Line 1,645:
writeln(fromPercentEncoded("http%3A%2F%2Ffoo%20bar%2F"));
writeln(fromUrlEncoded("http%3A%2F%2Ffoo+bar%2F"));
end func;</langsyntaxhighlight>
 
{{out}}
Line 1,655:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">func urldecode(str) {
str.gsub!('+', ' ');
str.gsub!(/\%([A-Fa-f0-9]{2})/, {|a| 'C'.pack(a.hex)});
Line 1,661:
}
 
say urldecode('http%3A%2F%2Ffoo+bar%2F'); # => "http://foo bar/"</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
let encoded = "http%3A%2F%2Ffoo%20bar%2F"
if let normal = encoded.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
println(normal)
}</langsyntaxhighlight>
 
=={{header|Tcl}}==
This code is careful to ensure that any untoward metacharacters in the input string still do not cause any problems.
<langsyntaxhighlight lang="tcl">proc urlDecode {str} {
set specialMap {"[" "%5B" "]" "%5D"}
set seqRE {%([0-9a-fA-F]{2})}
Line 1,679:
set modStr [regsub -all $seqRE [string map $specialMap $str] $replacement]
return [encoding convertfrom utf-8 [subst -nobackslash -novariable $modStr]]
}</langsyntaxhighlight>
Demonstrating:
<langsyntaxhighlight lang="tcl">puts [urlDecode "http%3A%2F%2Ffoo%20bar%2F"]</langsyntaxhighlight>
{{out}}
<pre>http://foo bar/</pre>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
url_encoded="http%3A%2F%2Ffoo%20bar%2F"
Line 1,695:
PRINT "encoded: ", url_encoded
PRINT "decoded: ", url_decoded
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,707:
{{works with|ksh}}
 
<langsyntaxhighlight lang="bash">urldecode() { local u="${1//+/ }"; printf '%b' "${u//%/\\x}"; }</langsyntaxhighlight>
 
Example:
 
<langsyntaxhighlight lang="bash">urldecode http%3A%2F%2Ffoo%20bar%2F
http://foo bar/
 
urldecode google.com/search?q=%60Abdu%27l-Bah%C3%A1
google.com/search?q=`Abdu'l-Bahároot@
</syntaxhighlight>
</lang>
 
 
 
<langsyntaxhighlight lang="bash">function urldecode
{
typeset encoded=$1 decoded= rest= c= c1= c2=
Line 1,784:
fi
}
</syntaxhighlight>
</lang>
 
=={{header|VBScript}}==
<langsyntaxhighlight VBScriptlang="vbscript">Function RegExTest(str,patrn)
Dim regEx
Set regEx = New RegExp
Line 1,831:
url = "http%3A%2F%2Ffoo%20bar%C3%A8%2F"
WScript.Echo "Encoded URL: " & url & vbCrLf &_
"Decoded URL: " & UrlDecode(url)</langsyntaxhighlight>
{{out}}
Line 1,838:
 
=={{header|Vlang}}==
<langsyntaxhighlight lang="vlang">import net.urllib
fn main() {
for escaped in [
Line 1,847:
println(u)
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,856:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/fmt" for Conv
 
var urlDecode = Fn.new { |enc|
Line 1,880:
"google.com/search?q=\%60Abdu\%27l-Bah\%C3\%A1"
]
for (enc in encs)System.print(urlDecode.call(enc))</langsyntaxhighlight>
 
{{out}}
Line 1,889:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">code Text=12;
string 0; \use zero-terminated strings
 
Line 1,911:
];
 
Text(0, Decode("http%3A%2F%2Ffoo%20bar%2f"))</langsyntaxhighlight>
 
{{out}}
Line 1,920:
=={{header|Yabasic}}==
{{trans|Phix}}
<langsyntaxhighlight Yabasiclang="yabasic">sub decode_url$(s$)
local res$, ch$
Line 1,938:
 
print decode_url$("http%3A%2F%2Ffoo%20bar%2F")
print decode_url$("google.com/search?q=%60Abdu%27l-Bah%C3%A1")</langsyntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">"http%3A%2F%2Ffoo%20bar%2F".pump(String, // push each char through these fcns:
fcn(c){ if(c=="%") return(Void.Read,2); return(Void.Skip,c) },// %-->read 2 chars else pass through
fcn(_,b,c){ (b+c).toInt(16).toChar() }) // "%" (ignored) "3"+"1"-->0x31-->"1"</langsyntaxhighlight>
{{out}}
<pre>http://foo bar/</pre>
or use libCurl:
<langsyntaxhighlight lang="zkl">var Curl=Import.lib("zklCurl");
Curl.urlDecode("http%3A%2F%2Ffoo%20bar%2F");</langsyntaxhighlight>
{{out}}<pre>http://foo bar/</pre>
10,327

edits