Code Monkey home page Code Monkey logo

libwww-form-urlencoded-perl's Introduction

Build Status

NAME

WWW::Form::UrlEncoded - parser and builder for application/x-www-form-urlencoded

SYNOPSIS

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 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)
    1. Ready empty array to store name and value
    1. For each divided string, apply next steps.
      1. If first character of string is ' ' (U+0020 SPACE), remove it.
      1. If string has =, let name be substring from start to first =, but excluding first =, and remains to be value. If there is no strings after first =, value to be empty string "". If first = is first character of the string, let key be empty string "". If string does not have any =, all of the string to be key and value to be empty string "".
      1. replace all + (U+002B) with ' ' (U+0020 SPACE).
      1. unescape name and value. push them to the array.
    1. 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 $str and return Array that contains key-value pairs.

  • $param:ArrayRef = parse_urlencoded_arrayref($str:String)

    parse $str and 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 $delim parameter 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.

SEE ALSO

CPAN already has some application/x-www-form-urlencoded parser modules like these.

They does not fully compatible with WWW::Form::UrlEncoded. Handling of empty key-value and supporting separator characters 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 [email protected]

libwww-form-urlencoded-perl's People

Contributors

deepin-ci-robot avatar zeno-sole avatar chenchongbiao avatar deepin-community-ci-bot[bot] avatar

Watchers

Han Gao avatar zccrs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.