ninenines / cowlib

Support library for manipulating Web protocols.
ISC License
279 stars 173 forks source link

cow_http_struct_hd:parse_dictionary fails to properly parse tokens #128

Closed RoadRunnr closed 2 years ago

RoadRunnr commented 2 years ago

cow_http_struct_hd:parse_dictionary/1 does detect tokens when they start with an APLHA, e.g.:

> cow_http_struct_hd:parse_dictionary(<<"token=abcxyz">>). 
[{<<"token">>,{item,{token,<<"abcxyz">>},[]}}]

However, according to RFC7230, Sect. 3.2.6. tokens can start with a number of specials characters. parse_dictionary/1 fails on them:

> cow_http_struct_hd:parse_dictionary(<<"token=5abcxyz">>).
** exception error: no function clause matching cow_http_struct_hd:parse_dict_before_sep(<<"abcxyz">>,[{<<"token">>,{item,5,[]}}]) (/usr/src/erlang/cowlib/src/cow_http_struct_hd.erl, line 84)

and

 cow_http_struct_hd:parse_dictionary(<<"token=!abcxyz">>).
** exception error: no function clause matching cow_http_struct_hd:parse_bare_item(<<"!abcxyz">>) (/usr/src/erlang/cowlib/src/cow_http_struct_hd.erl, line 179)
     in function  cow_http_struct_hd:parse_item1/1 (/usr/src/erlang/cowlib/src/cow_http_struct_hd.erl, line 106)
     in call from cow_http_struct_hd:parse_dict_key/3 (/usr/src/erlang/cowlib/src/cow_http_struct_hd.erl, line 72)
essen commented 2 years ago

You are looking at the wrong spec, this module implements structured headers: https://datatracker.ietf.org/doc/html/rfc8941