diff --git a/src/llhttp/http.ts b/src/llhttp/http.ts index 91d995ef..5a670931 100644 --- a/src/llhttp/http.ts +++ b/src/llhttp/http.ts @@ -797,7 +797,7 @@ export class HTTP { n('chunk_size_otherwise') .match('\r', n('chunk_size_almost_done')) - .match([ ';', ' ' ], n('chunk_parameters')) + .match('; ', n('chunk_parameters')) .otherwise(p.error(ERROR.INVALID_CHUNK_SIZE, 'Invalid character in chunk size')); diff --git a/test/request/transfer-encoding.md b/test/request/transfer-encoding.md index 194bf16e..53831602 100644 --- a/test/request/transfer-encoding.md +++ b/test/request/transfer-encoding.md @@ -232,6 +232,37 @@ off=157 chunk complete off=160 chunk header len=0 ``` +### No semicolon before chunk parameters + + +```http +POST /chunked_w_unicorns_after_length HTTP/1.1 +Host: localhost +Transfer-encoding: chunked + +2 erfrferferf +aa +0 rrrr + + +``` + +```log +off=0 message begin +off=5 len=32 span[url]="/chunked_w_unicorns_after_length" +off=38 url complete +off=48 len=4 span[header_field]="Host" +off=53 header_field complete +off=54 len=9 span[header_value]="localhost" +off=65 header_value complete +off=65 len=17 span[header_field]="Transfer-encoding" +off=83 header_field complete +off=84 len=7 span[header_value]="chunked" +off=93 header_value complete +off=95 headers complete method=3 v=1/1 flags=208 content_length=0 +off=96 error code=12 reason="Invalid character in chunk size" +``` + ## Ignoring `pigeons` Requests cannot have invalid `Transfer-Encoding`. It is impossible to determine @@ -598,5 +629,5 @@ off=37 header_field complete off=38 len=7 span[header_value]="chunked" off=47 header_value complete off=49 headers complete method=4 v=1/1 flags=208 content_length=0 -off=51 error code=2 reason="Invalid character in chunk parameters" +off=50 error code=12 reason="Invalid character in chunk size" ``` diff --git a/test/response/transfer-encoding.md b/test/response/transfer-encoding.md index 42fb588d..b606c660 100644 --- a/test/response/transfer-encoding.md +++ b/test/response/transfer-encoding.md @@ -33,19 +33,7 @@ off=61 header_field complete off=62 len=7 span[header_value]="chunked" off=71 header_value complete off=73 headers complete status=200 v=1/1 flags=208 content_length=0 -off=79 chunk header len=37 -off=79 len=35 span[body]="This is the data in the first chunk" -off=114 len=1 span[body]=cr -off=115 len=1 span[body]=lf -off=118 chunk complete -off=122 chunk header len=28 -off=122 len=26 span[body]="and this is the second one" -off=148 len=1 span[body]=cr -off=149 len=1 span[body]=lf -off=152 chunk complete -off=157 chunk header len=0 -off=159 chunk complete -off=159 message complete +off=75 error code=12 reason="Invalid character in chunk size" ``` ### `chunked` before other transfer-encoding @@ -148,4 +136,36 @@ off=75 len=1 span[body]=cr off=76 len=1 span[body]=lf off=77 len=1 span[body]=cr off=78 len=1 span[body]=lf -``` \ No newline at end of file +``` + +### No semicolon before chunk parameters + + +```http +HTTP/1.1 200 OK +Host: localhost +Transfer-encoding: chunked + +2 erfrferferf +aa +0 rrrr + + +``` + +```log +off=0 message begin +off=13 len=2 span[status]="OK" +off=17 status complete +off=17 len=4 span[header_field]="Host" +off=22 header_field complete +off=23 len=9 span[header_value]="localhost" +off=34 header_value complete +off=34 len=17 span[header_field]="Transfer-encoding" +off=52 header_field complete +off=53 len=7 span[header_value]="chunked" +off=62 header_value complete +off=64 headers complete status=200 v=1/1 flags=208 content_length=0 +off=65 error code=12 reason="Invalid character in chunk size" +``` +