add implied LWS token handling after chunk-size token.
@@ -114,6 +114,42 @@ | ||
114 | 114 | "\r\n" |
115 | 115 | }; |
116 | 116 | |
117 | +LOCAL UB testdata_chunked_09[] = { | |
118 | + "1A \r\n" | |
119 | + "abcfefghijklmnopqrstuvwxyz\r\n" | |
120 | + "1a \r\n" | |
121 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" | |
122 | + "000 \r\n" | |
123 | + "\r\n" | |
124 | +}; | |
125 | + | |
126 | +LOCAL UB testdata_chunked_10[] = { | |
127 | + "1a ;name=value\r\n" | |
128 | + "abcfefghijklmnopqrstuvwxyz\r\n" | |
129 | + "1A ;name\r\n" | |
130 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" | |
131 | + "0 ;name=value\r\n" | |
132 | + "\r\n" | |
133 | +}; | |
134 | + | |
135 | +LOCAL UB testdata_chunked_11[] = { | |
136 | + "1A\t\r\n" | |
137 | + "abcfefghijklmnopqrstuvwxyz\r\n" | |
138 | + "1a\t\t\r\n" | |
139 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" | |
140 | + "000\t\r\n" | |
141 | + "\r\n" | |
142 | +}; | |
143 | + | |
144 | +LOCAL UB testdata_chunked_12[] = { | |
145 | + "1a\t;name=value\r\n" | |
146 | + "abcfefghijklmnopqrstuvwxyz\r\n" | |
147 | + "1A\t\t;name\r\n" | |
148 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" | |
149 | + "0\t;name=value\r\n" | |
150 | + "\r\n" | |
151 | +}; | |
152 | + | |
117 | 153 | LOCAL UNITTEST_RESULT test_http_transferdecoder_common_perone(HTTP_TRANSFERCODING_TYPE type, UB *testdata, W testdata_len, W devide_len, UB *expected, W expected_len) |
118 | 154 | { |
119 | 155 | http_transferdecoder_t decoder; |
@@ -302,6 +338,42 @@ | ||
302 | 338 | return test_http_transferdecoder_common(HTTP_TRANSFERCODING_TYPE_CHUNKED, testdata, testdata_len, expected, expected_len); |
303 | 339 | } |
304 | 340 | |
341 | +LOCAL UNITTEST_RESULT test_http_transferdecoder_chunked_9() | |
342 | +{ | |
343 | + UB *testdata = testdata_chunked_09; | |
344 | + W testdata_len = strlen(testdata_chunked_09); | |
345 | + UB *expected = testdata_identity_01; | |
346 | + W expected_len = strlen(testdata_identity_01); | |
347 | + return test_http_transferdecoder_common(HTTP_TRANSFERCODING_TYPE_CHUNKED, testdata, testdata_len, expected, expected_len); | |
348 | +} | |
349 | + | |
350 | +LOCAL UNITTEST_RESULT test_http_transferdecoder_chunked_10() | |
351 | +{ | |
352 | + UB *testdata = testdata_chunked_10; | |
353 | + W testdata_len = strlen(testdata_chunked_10); | |
354 | + UB *expected = testdata_identity_01; | |
355 | + W expected_len = strlen(testdata_identity_01); | |
356 | + return test_http_transferdecoder_common(HTTP_TRANSFERCODING_TYPE_CHUNKED, testdata, testdata_len, expected, expected_len); | |
357 | +} | |
358 | + | |
359 | +LOCAL UNITTEST_RESULT test_http_transferdecoder_chunked_11() | |
360 | +{ | |
361 | + UB *testdata = testdata_chunked_11; | |
362 | + W testdata_len = strlen(testdata_chunked_11); | |
363 | + UB *expected = testdata_identity_01; | |
364 | + W expected_len = strlen(testdata_identity_01); | |
365 | + return test_http_transferdecoder_common(HTTP_TRANSFERCODING_TYPE_CHUNKED, testdata, testdata_len, expected, expected_len); | |
366 | +} | |
367 | + | |
368 | +LOCAL UNITTEST_RESULT test_http_transferdecoder_chunked_12() | |
369 | +{ | |
370 | + UB *testdata = testdata_chunked_12; | |
371 | + W testdata_len = strlen(testdata_chunked_12); | |
372 | + UB *expected = testdata_identity_01; | |
373 | + W expected_len = strlen(testdata_identity_01); | |
374 | + return test_http_transferdecoder_common(HTTP_TRANSFERCODING_TYPE_CHUNKED, testdata, testdata_len, expected, expected_len); | |
375 | +} | |
376 | + | |
305 | 377 | EXPORT VOID test_http_transferdecoder_main(unittest_driver_t *driver) |
306 | 378 | { |
307 | 379 | UNITTEST_DRIVER_REGIST(driver, test_http_transferdecoder_identity_1); |
@@ -313,4 +385,8 @@ | ||
313 | 385 | UNITTEST_DRIVER_REGIST(driver, test_http_transferdecoder_chunked_6); |
314 | 386 | UNITTEST_DRIVER_REGIST(driver, test_http_transferdecoder_chunked_7); |
315 | 387 | UNITTEST_DRIVER_REGIST(driver, test_http_transferdecoder_chunked_8); |
388 | + UNITTEST_DRIVER_REGIST(driver, test_http_transferdecoder_chunked_9); | |
389 | + UNITTEST_DRIVER_REGIST(driver, test_http_transferdecoder_chunked_10); | |
390 | + UNITTEST_DRIVER_REGIST(driver, test_http_transferdecoder_chunked_11); | |
391 | + UNITTEST_DRIVER_REGIST(driver, test_http_transferdecoder_chunked_12); | |
316 | 392 | } |
@@ -116,7 +116,28 @@ | ||
116 | 116 | parser->state = HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_SIZE_CR; |
117 | 117 | break; |
118 | 118 | } |
119 | + if ((ch == ' ')||(ch == '\t')) { | |
120 | + parser->state = HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_SIZE_IMPLIED_LWS; | |
121 | + break; | |
122 | + } | |
119 | 123 | return HTTP_CHUNKEDBODYPARSER_RESULT_ERROR; |
124 | + case HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_SIZE_IMPLIED_LWS: | |
125 | + if (ch == ';') { | |
126 | + if (parser->chunk_size == 0) { | |
127 | + parser->state = HTTP_CHUNKEDBODYPARSER_STATE_LAST_CHUNK_EXTENTION; | |
128 | + } else { | |
129 | + parser->state = HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_EXTENTION; | |
130 | + } | |
131 | + break; | |
132 | + } | |
133 | + if (ch == '\r') { | |
134 | + parser->state = HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_SIZE_CR; | |
135 | + break; | |
136 | + } | |
137 | + if ((ch == ' ')||(ch == '\t')) { | |
138 | + break; | |
139 | + } | |
140 | + return HTTP_CHUNKEDBODYPARSER_RESULT_ERROR; | |
120 | 141 | case HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_SIZE_CR: |
121 | 142 | DP_STATE("CHUNK_SIZE_CR"); |
122 | 143 | if (ch == '\n') { |
@@ -64,6 +64,7 @@ | ||
64 | 64 | struct http_chunkedbodyparser_t_ { |
65 | 65 | enum { |
66 | 66 | HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_SIZE, |
67 | + HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_SIZE_IMPLIED_LWS, | |
67 | 68 | HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_SIZE_CR, |
68 | 69 | HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_DATA, |
69 | 70 | HTTP_CHUNKEDBODYPARSER_STATE_CHUNK_DATA_END, |