1WWW::Form::UrlEncoded(3U)ser Contributed Perl DocumentatiWoWnW::Form::UrlEncoded(3)
2
3
4
6 WWW::Form::UrlEncoded - parser and builder for
7 application/x-www-form-urlencoded
8
10 use WWW::Form::UrlEncoded qw/parse_urlencoded build_urlencoded/;
11
12 my $query_string = "foo=bar&baz=param";
13 my @params = parse_urlencoded($query_string);
14 # ('foo','bar','baz','param')
15
16 my $query_string = build_urlencoded('foo','bar','baz','param');
17 # "foo=bar&baz=param";
18
20 WWW::Form::UrlEncoded provides application/x-www-form-urlencoded parser
21 and builder. This module aims to have compatibility with other CPAN
22 modules like HTTP::Body's urlencoded parser.
23
24 This module try to use WWW::Form::UrlEncoded::XS by default and fail to
25 it, use WWW::Form::UrlEncoded::PP instead
26
27 Parser rules
28 WWW::Form::UrlEncoded parsed string in this rule.
29
30 1. Split application/x-www-form-urlencoded payload by "&" (U+0026) or
31 ";" (U+003B)
32 2. Ready empty array to store "name" and "value"
33 3. For each divided string, apply next steps.
34 1. If first character of string is ' ' (U+0020 SPACE), remove it.
35 2. If string has "=", let name be substring from start to first
36 "=", but excluding first "=", and remains to be value. If there is
37 no strings after first "=", value to be empty string "". If first
38 "=" is first character of the string, let key be empty string "".
39 If string does not have any "=", all of the string to be key and
40 value to be empty string "".
41 3. replace all "+" (U+002B) with ' ' (U+0020 SPACE).
42 4. unescape name and value. push them to the array.
43 4. return the array.
44
45 Test data
46 'a=b&c=d' => ["a","b","c","d"]
47 'a=b;c=d' => ["a","b","c","d"]
48 'a=1&b=2;c=3' => ["a","1","b","2","c","3"]
49 'a==b&c==d' => ["a","=b","c","=d"]
50 'a=b& c=d' => ["a","b","c","d"]
51 'a=b; c=d' => ["a","b","c","d"]
52 'a=b; c =d' => ["a","b","c ","d"]
53 'a=b;c= d ' => ["a","b","c"," d "]
54 'a=b&+c=d' => ["a","b"," c","d"]
55 'a=b&+c+=d' => ["a","b"," c ","d"]
56 'a=b&c=+d+' => ["a","b","c"," d "]
57 'a=b&%20c=d' => ["a","b"," c","d"]
58 'a=b&%20c%20=d' => ["a","b"," c ","d"]
59 'a=b&c=%20d%20' => ["a","b","c"," d "]
60 'a&c=d' => ["a","","c","d"]
61 'a=b&=d' => ["a","b","","d"]
62 'a=b&=' => ["a","b","",""]
63 '&' => ["","","",""]
64 '=' => ["",""]
65 '' => []
66
68 @param = parse_urlencoded($str:String)
69 parse $str and return Array that contains key-value pairs.
70
71 $param:ArrayRef = parse_urlencoded_arrayref($str:String)
72 parse $str and return ArrayRef that contains key-value pairs.
73
74 $string = build_urlencoded(@param)
75 $string = build_urlencoded(@param, $delim)
76 $string = build_urlencoded(\@param)
77 $string = build_urlencoded(\@param, $delim)
78 $string = build_urlencoded(\%param)
79 $string = build_urlencoded(\%param, $delim)
80 build urlencoded string from param. build_urlencoded accepts
81 arrayref and hashref values.
82
83 build_urlencoded( foo => 1, foo => 2);
84 build_urlencoded( foo => [1,2] );
85 build_urlencoded( [ foo => 1, foo => 2 ] );
86 build_urlencoded( [foo => [1,2]] );
87 build_urlencoded( {foo => [1,2]} );
88
89 If $delim parameter is passed, this function use it instead of
90 using "&".
91
92 $string = build_urlencoded_utf8(...)
93 This function is almost same as "build_urlencoded".
94 build_urlencoded_utf8 call "utf8::encode" for all parameters.
95
97 ยท WWW_FORM_URLENCODED_PP
98
99 If true, WWW::Form::UrlEncoded force to load
100 WWW::Form::UrlEncoded::PP.
101
103 CPAN already has some application/x-www-form-urlencoded parser modules
104 like these.
105
106 URL::Encode
107 URL::Encode::XS
108 Text::QueryString
109
110 They does not fully compatible with WWW::Form::UrlEncoded. Handling of
111 empty key-value and supporting separator characters are different.
112
114 Copyright (C) Masahiro Nagano.
115
116 This library is free software; you can redistribute it and/or modify it
117 under the same terms as Perl itself.
118
120 Masahiro Nagano <kazeburo@gmail.com>
121
122
123
124perl v5.30.0 2019-07-26 WWW::Form::UrlEncoded(3)