• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂662 (tree)
時間2015-03-15 19:37:40
作者ornse01

Log Message

fix cookie
- fix bug for Set-Cookie attribute's value is not exist
- case insensivity workaround.

Change Summary

差異

--- bchan/trunk/src/setcookieheader.c (revision 661)
+++ bchan/trunk/src/setcookieheader.c (revision 662)
@@ -1,7 +1,7 @@
11 /*
22 * setcookieheader.c
33 *
4- * Copyright (c) 2011 project bchan
4+ * Copyright (c) 2011-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -109,6 +109,11 @@
109109 if (ch == ' ') {
110110 break;
111111 }
112+ if (ch == ';') {
113+ lexer->state = HTTPCOOKIEGENERAL_STATE_SEARCH_ATTR;
114+ *result = HTTPCOOKIEGENERAL_RESULT_AVPAIR_END;
115+ break;
116+ }
112117 lexer->state = HTTPCOOKIEGENERAL_STATE_READ_VALUE;
113118 *result = HTTPCOOKIEGENERAL_RESULT_VALUE;
114119 break;
@@ -322,6 +327,13 @@
322327 }
323328
324329 LOCAL tokenchecker_valuetuple_t nList_attr[] = {
330+ {"Comment", SETCOOKIEPARSER_ATTR_COMMENT},
331+ {"Domain", SETCOOKIEPARSER_ATTR_DOMAIN},
332+ {"Expires", SETCOOKIEPARSER_ATTR_EXPIRES},
333+ {"Max-age", SETCOOKIEPARSER_ATTR_MAX_AGE},
334+ {"Path", SETCOOKIEPARSER_ATTR_PATH},
335+ {"Secure", SETCOOKIEPARSER_ATTR_SECURE},
336+ {"Versions", SETCOOKIEPARSER_ATTR_VERSION},
325337 {"comment", SETCOOKIEPARSER_ATTR_COMMENT},
326338 {"domain", SETCOOKIEPARSER_ATTR_DOMAIN},
327339 {"expires", SETCOOKIEPARSER_ATTR_EXPIRES},
@@ -336,7 +348,7 @@
336348 {
337349 parser->state = SETCOOKIEPARSER_STATE_SEARCH_ATTR;
338350 parser->attr = 0;
339- tokenchecker_initialize(&(parser->attrchecker), nList_attr, 7, eToken_attr);
351+ tokenchecker_initialize(&(parser->attrchecker), nList_attr, 14, eToken_attr);
340352 return httpcookiegeneral_initialize(&parser->lexer);
341353 }
342354
--- bchan/trunk/src/test_setcookieheader.c (revision 661)
+++ bchan/trunk/src/test_setcookieheader.c (revision 662)
@@ -1,7 +1,7 @@
11 /*
22 * test_setcookieheader.c
33 *
4- * Copyright (c) 2011-2012 project bchan
4+ * Copyright (c) 2011-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -38,6 +38,7 @@
3838 LOCAL UB test_setcookieheader_testdata_02[] = " HAP=0000000; expires=Friday, 01-Jan-2016 00:00:00 GMT; path=/; domain=.2ch.net";
3939 LOCAL UB test_setcookieheader_testdata_03[] = " num=123456; expires=Sun, 10-Jun-2001 12:00:00 GMT; path=/HTTP/";
4040 LOCAL UB test_setcookieheader_testdata_04[] = " param2=GHIJKL; expires=Mon, 31-Dec-2001 23:59:59 GMT; path=/; secure";
41+LOCAL UB test_setcookieheader_testdata_05[] = " NAME=; Expires=Friday, 01-Jan-2016 00:00:00 GMT; Path=/";
4142
4243 typedef struct {
4344 UB *attr_name_exptd;
@@ -410,6 +411,35 @@
410411 return UNITTEST_RESULT_PASS;
411412 }
412413
414+LOCAL UNITTEST_RESULT test_setcookieheader_5()
415+{
416+ setcookieparser_t parser;
417+ W i,err,len,res_len;
418+ setcookieparser_result_t *res;
419+ test_cookieresult_t check;
420+
421+ test_cookieresult_initialize(&check, "NAME", "", "", "", /*"Friday, 01-Jan-2016 00:00:00"*/0x3a4e7700, "", "/", "", False);
422+
423+ err = setcookieparser_initialize(&parser);
424+ if (err < 0) {
425+ return UNITTEST_RESULT_FAIL;
426+ }
427+ len = strlen(test_setcookieheader_testdata_05);
428+ for (i = 0; i < len; i++) {
429+ setcookieparser_inputchar(&parser, test_setcookieheader_testdata_05[i], &res, &res_len);
430+ test_cookieresult_inputresult_array(&check, res, res_len);
431+ }
432+ setcookieparser_endinput(&parser, &res, &res_len);
433+ test_cookieresult_inputresult_array(&check, res, res_len);
434+ setcookieparser_finalize(&parser);
435+
436+ if (test_cookieresult_checkexpected(&check) == False) {
437+ return UNITTEST_RESULT_FAIL;
438+ }
439+
440+ return UNITTEST_RESULT_PASS;
441+}
442+
413443 EXPORT VOID test_setcookieheader_main(unittest_driver_t *driver)
414444 {
415445 UNITTEST_DRIVER_REGIST(driver, test_setcookieheader_1);
@@ -416,4 +446,5 @@
416446 UNITTEST_DRIVER_REGIST(driver, test_setcookieheader_2);
417447 UNITTEST_DRIVER_REGIST(driver, test_setcookieheader_3);
418448 UNITTEST_DRIVER_REGIST(driver, test_setcookieheader_4);
449+ UNITTEST_DRIVER_REGIST(driver, test_setcookieheader_5);
419450 }
Show on old repository browser