.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "URI::Escape 3" .TH URI::Escape 3 "2015-06-26" "perl v5.12.5" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" URI::Escape \- Percent\-encode and percent\-decode unsafe characters .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& use URI::Escape; \& $safe = uri_escape("10% is enough\en"); \& $verysafe = uri_escape("foo", "\e0\-\e377"); \& $str = uri_unescape($safe); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides functions to percent-encode and percent-decode \s-1URI\s0 strings as defined by \s-1RFC\s0 3986. Percent-encoding \s-1URI\s0's is informally called \*(L"\s-1URI\s0 escaping\*(R". This is the terminology used by this module, which predates the formalization of the terms by the \s-1RFC\s0 by several years. .PP A \s-1URI\s0 consists of a restricted set of characters. The restricted set of characters consists of digits, letters, and a few graphic symbols chosen from those common to most of the character encodings and input facilities available to Internet users. They are made up of the \&\*(L"unreserved\*(R" and \*(L"reserved\*(R" character sets as defined in \s-1RFC\s0 3986. .PP .Vb 4 \& unreserved = ALPHA / DIGIT / "\-" / "." / "_" / "~" \& reserved = ":" / "/" / "?" / "#" / "[" / "]" / "@" \& "!" / "$" / "&" / "\*(Aq" / "(" / ")" \& / "*" / "+" / "," / ";" / "=" .Ve .PP In addition, any byte (octet) can be represented in a \s-1URI\s0 by an escape sequence: a triplet consisting of the character \*(L"%\*(R" followed by two hexadecimal digits. A byte can also be represented directly by a character, using the US-ASCII character for that octet. .PP Some of the characters are \fIreserved\fR for use as delimiters or as part of certain \s-1URI\s0 components. These must be escaped if they are to be treated as ordinary data. Read \s-1RFC\s0 3986 for further details. .PP The functions provided (and exported by default) from this module are: .ie n .IP "uri_escape( $string )" 4 .el .IP "uri_escape( \f(CW$string\fR )" 4 .IX Item "uri_escape( $string )" .PD 0 .ie n .IP "uri_escape( $string, $unsafe )" 4 .el .IP "uri_escape( \f(CW$string\fR, \f(CW$unsafe\fR )" 4 .IX Item "uri_escape( $string, $unsafe )" .PD Replaces each unsafe character in the \f(CW$string\fR with the corresponding escape sequence and returns the result. The \f(CW$string\fR argument should be a string of bytes. The \fIuri_escape()\fR function will croak if given a characters with code above 255. Use \fIuri_escape_utf8()\fR if you know you have such chars or/and want chars in the 128 .. 255 range treated as \&\s-1UTF\-8\s0. .Sp The \fIuri_escape()\fR function takes an optional second argument that overrides the set of characters that are to be escaped. The set is specified as a string that can be used in a regular expression character class (between [ ]). E.g.: .Sp .Vb 3 \& "\ex00\-\ex1f\ex7f\-\exff" # all control and hi\-bit characters \& "a\-z" # all lower case characters \& "^A\-Za\-z" # everything not a letter .Ve .Sp The default set of characters to be escaped is all those which are \&\fInot\fR part of the \f(CW\*(C`unreserved\*(C'\fR character class shown above as well as the reserved characters. I.e. the default is: .Sp .Vb 1 \& "^A\-Za\-z0\-9\e\-\e._~" .Ve .ie n .IP "uri_escape_utf8( $string )" 4 .el .IP "uri_escape_utf8( \f(CW$string\fR )" 4 .IX Item "uri_escape_utf8( $string )" .PD 0 .ie n .IP "uri_escape_utf8( $string, $unsafe )" 4 .el .IP "uri_escape_utf8( \f(CW$string\fR, \f(CW$unsafe\fR )" 4 .IX Item "uri_escape_utf8( $string, $unsafe )" .PD Works like \fIuri_escape()\fR, but will encode chars as \s-1UTF\-8\s0 before escaping them. This makes this function able to deal with characters with code above 255 in \f(CW$string\fR. Note that chars in the 128 .. 255 range will be escaped differently by this function compared to what \&\fIuri_escape()\fR would. For chars in the 0 .. 127 range there is no difference. .Sp Equivalent to: .Sp .Vb 2 \& utf8::encode($string); \& my $uri = uri_escape($string); .Ve .Sp Note: JavaScript has a function called \fIescape()\fR that produces the sequence \*(L"%uXXXX\*(R" for chars in the 256 .. 65535 range. This function has really nothing to do with \s-1URI\s0 escaping but some folks got confused since it \*(L"does the right thing\*(R" in the 0 .. 255 range. Because of this you sometimes see \*(L"URIs\*(R" with these kind of escapes. The JavaScript \fIencodeURIComponent()\fR function is similar to \fIuri_escape_utf8()\fR. .IP "uri_unescape($string,...)" 4 .IX Item "uri_unescape($string,...)" Returns a string with each \f(CW%XX\fR sequence replaced with the actual byte (octet). .Sp This does the same as: .Sp .Vb 1 \& $string =~ s/%([0\-9A\-Fa\-f]{2})/chr(hex($1))/eg; .Ve .Sp but does not modify the string in-place as this \s-1RE\s0 would. Using the \&\fIuri_unescape()\fR function instead of the \s-1RE\s0 might make the code look cleaner and is a few characters less to type. .Sp In a simple benchmark test I did, calling the function (instead of the inline \s-1RE\s0 above) if a few chars were unescaped was something like 40% slower, and something like 700% slower if none were. If you are going to unescape a lot of times it might be a good idea to inline the \s-1RE\s0. .Sp If the \fIuri_unescape()\fR function is passed multiple strings, then each one is returned unescaped. .PP The module can also export the \f(CW%escapes\fR hash, which contains the mapping from all 256 bytes to the corresponding escape codes. Lookup in this hash is faster than evaluating \f(CW\*(C`sprintf("%%%02X", ord($byte))\*(C'\fR each time. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\s-1URI\s0 .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 1995\-2004 Gisle Aas. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.