WWW::Form::UrlEncoded3pm
Parser and builder for application/x-www-form-urlencoded
Usage
use WWW::Form::UrlEncoded qw/parse_urlencoded build_urlencoded/;my $query_string = "foo=bar&baz=param";my @params = parse_urlencoded($query_string);# ('foo','bar','baz','param')my $query_string = build_urlencoded('foo','bar','baz','param');# "foo=bar&baz=param";
Overview
WWW::Form::UrlEncoded provides application/x-www-form-urlencoded parser and builder. This module aims to have compatibility with other CPAN modules like HTTP::Body's urlencoded parser.
This module try to use WWW::Form::UrlEncoded::XS by default and fail to it, use WWW::Form::UrlEncoded::PP instead
Parser rules
WWW::Form::UrlEncoded parsed string in this rule.
- 1. Split application/x-www-form-urlencoded payload by "&" (U+0026) or ";" (U+003B)
- 2. Ready empty array to store "name" and "value"
- 3. For each divided string, apply next steps.
-
- 1. If first character of string is ' ' (U+0020 SPACE), remove it.
- 2. If string has "=", let
namebe substring from start to first "=", but excluding first "=", and remains to bevalue. If there is no strings after first "=",valueto be empty string "". If first "=" is first character of the string, letkeybe empty string "". If string does not have any "=", all of the string to bekeyandvalueto be empty string "".
- 3. replace all "+" (U+002B) with ' ' (U+0020 SPACE).
- 4. unescape
nameandvalue. push them to the array.
- 4. return the array.
Test data
'a=b&c=d' => ["a","b","c","d"]'a=b;c=d' => ["a","b","c","d"]'a=1&b=2;c=3' => ["a","1","b","2","c","3"]'a==b&c==d' => ["a","=b","c","=d"]'a=b& c=d' => ["a","b","c","d"]'a=b; c=d' => ["a","b","c","d"]'a=b; c =d' => ["a","b","c ","d"]'a=b;c= d ' => ["a","b","c"," d "]'a=b&+c=d' => ["a","b"," c","d"]'a=b&+c+=d' => ["a","b"," c ","d"]'a=b&c=+d+' => ["a","b","c"," d "]'a=b&%20c=d' => ["a","b"," c","d"]'a=b&%20c%20=d' => ["a","b"," c ","d"]'a=b&c=%20d%20' => ["a","b","c"," d "]'a&c=d' => ["a","","c","d"]'a=b&=d' => ["a","b","","d"]'a=b&=' => ["a","b","",""]'&' => ["","","",""]'=' => ["",""]'' => []
Function
- @param = parse_urlencoded($str:String)
-
parse
$strand return Array that contains key-value pairs.
- $param:ArrayRef = parse_urlencoded_arrayref($str:String)
-
parse
$strand return ArrayRef that contains key-value pairs.
- $string = build_urlencoded(@param)
- $string = build_urlencoded(@param, $delim)
- $string = build_urlencoded(\@param)
- $string = build_urlencoded(\@param, $delim)
- $string = build_urlencoded(\%param)
- $string = build_urlencoded(\%param, $delim)
-
build urlencoded string from
param. build_urlencoded accepts arrayref and hashref values.build_urlencoded( foo => 1, foo => 2);build_urlencoded( foo => [1,2] );build_urlencoded( [ foo => 1, foo => 2 ] );build_urlencoded( [foo => [1,2]] );build_urlencoded( {foo => [1,2]} );If
$delimparameter is passed, this function use it instead of using"&".
- $string = build_urlencoded_utf8(...)
-
This function is almost same as
"build_urlencoded". build_urlencoded_utf8 call"utf8::encode"for all parameters.
Environment value
- •
-
WWW_FORM_URLENCODED_PP
If true, WWW::Form::UrlEncoded force to load WWW::Form::UrlEncoded::PP.
Releases
5 releases since Debian 9 (Stretch); the text changed 3 times.