WWW::F...Encoded(3pm)
π NAME π
WWW::Form::UrlEncoded is literally the parser and builder for application/x-www-form-urlencoded, no cap. This page is WWW::F...Encoded(3pm), from User Contributed Perl Documentation, and itβs here to help you slay your form data π
β¨ SYNOPSIS β¨
Okay so first you import the functions, bestie:
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";
π DESCRIPTION π
WWW::Form::UrlEncoded provides an application/x-www-form-urlencoded parser and builder. Its whole goal is compatibility with other CPAN modules, like HTTP::Bodyβs urlencoded parser π«Ά
This module tries to use WWW::Form::UrlEncoded::XS by default, and if that fails, it uses WWW::Form::UrlEncoded::PP instead β¨
π§ Parser rules π§
WWW::Form::UrlEncoded parses strings by these rules:
- Split the
application/x-www-form-urlencodedpayload by&(U+0026) or;(U+003B). - Make an empty array ready to store
"name"and"value". - For each divided string, apply the next steps.
- If the first character of the string is
' '(U+0020 SPACE), remove it. - If the string has
"=", let name be the substring from the start to the first"=", but excluding the first"=", and the rest becomes value. If there are no strings after the first"=", value is the empty string"". If the first"="is the first character of the string, let key be the empty string"". If the string does not have any"=", all of the string becomes key and value becomes the empty string"". - Replace all
"+"(U+002B) with' '(U+0020 SPACE). - Unescape name and value. Push them to the array.
- If the first character of the string is
- Return the array.
π Test data π
Vibe check, these are the exact test mappings:
'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 an Array that contains key-value pairs π$param:ArrayRef = parse_urlencoded_arrayref($str:String)β parse$strand return an ArrayRef that contains key-value pairs β¨
These are all the build_urlencoded signatures, bestie:
$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)
For all of those build_urlencoded signatures: build a 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 $delim is passed, this function uses it instead of using "&" π¦
$string = build_urlencoded_utf8(...)β this function is almost the same as"build_urlencoded".build_urlencoded_utf8calls"utf8::encode"for all parameters πΈ
π ENVIRONMENT VALUE π
WWW_FORM_URLENCODED_PPβ if true,WWW::Form::UrlEncodedforces itself to loadWWW::Form::UrlEncoded::PPπ
π SEE ALSO π
CPAN already has some application/x-www-form-urlencoded parser modules, like these:
URL::EncodeURL::Encode::XSText::QueryString
Theyβre not fully compatible with WWW::Form::UrlEncoded. The way they handle empty key-value and the separator characters they support are different π¦
π LICENSE π
Copyright (C) Masahiro Nagano.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π AUTHOR π
Masahiro Nagano <kazeburo@gmail.com>
Signed, sealed, delivered with perl v5.42.0 on 2020-10-21, page WWW::F...Encoded(3pm) β mwah, bestie ππ«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-WWW-Form-UrlEncoded 0.26-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-WWW-Form-UrlEncoded 0.26-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-WWW-Form-UrlEncoded 0.26-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-WWW-Form-UrlEncoded 0.26-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms