Crystal: HTTP::Params.parse query string "&&" bug

Created on 11 Nov 2017  路  3Comments  路  Source: crystal-lang/crystal

parse params in crystal

icr(0.23.1) > HTTP::Params.parse("&&")
 => HTTP::Params(@raw_params={"" => ["", "", ""]})

parse params in ruby

2.4.1 :029 > CGI::parse("&&")
 => {} 

Crystal 0.23.1 (2017-10-12) LLVM 4.0.1

bug stdlib

Most helpful comment

What about these examples?
```cr
HTTP::Params.parse("a=b&&c=d") # => HTTP::Params(@raw_params={"a" => ["b"], "" => [""], "c" => ["d"]})
HTTP::Params.parse("&&c=d") # => HTTP::Params(@raw_params={"" => ["", ""], "c" => ["d"]})
HTTP::Params.parse("a=b&&") # => HTTP::Params(@raw_params={"a" => ["b"], "" => ["", ""]})

All 3 comments

What about these examples?
```cr
HTTP::Params.parse("a=b&&c=d") # => HTTP::Params(@raw_params={"a" => ["b"], "" => [""], "c" => ["d"]})
HTTP::Params.parse("&&c=d") # => HTTP::Params(@raw_params={"" => ["", ""], "c" => ["d"]})
HTTP::Params.parse("a=b&&") # => HTTP::Params(@raw_params={"a" => ["b"], "" => ["", ""]})

That is still works.

$ bin/crystal test.cr 
HTTP::Params.parse("a=b&&c=d") # => HTTP::Params(@raw_params={"a" => ["b"], "c" => ["d"]})
HTTP::Params.parse("&&c=d") # => HTTP::Params(@raw_params={"c" => ["d"]})
HTTP::Params.parse("a=b&&") # => HTTP::Params(@raw_params={"a" => ["b"]})

Because two & split the string into three parts, and remove both key and value are empty. Do I add these tests? @RX14

@akiicat sorry, my bad! I was testing those examples with the wrong compiler and thought they were broken. You can add them to the specs if you want but it's fine without.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  60Comments

benoist picture benoist  路  59Comments

farleyknight picture farleyknight  路  64Comments

asterite picture asterite  路  71Comments

chocolateboy picture chocolateboy  路  87Comments