Skip to content

Commit

Permalink
Merge pull request #37 from ngtcp2/more-displaystring-tests
Browse files Browse the repository at this point in the history
Add more display string tests
  • Loading branch information
tatsuhiro-t authored Jan 25, 2024
2 parents 0d1d495 + 72c07e6 commit c36bc9a
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions sfparse_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1554,9 +1554,10 @@ void test_sf_parser_dispstring(void) {
sf_parser sfp;
sf_value val;
sf_vec decoded;
uint8_t buf[64];
uint8_t buf[128];

/* https://github.com/httpwg/structured-field-tests/blob/main/display-string.json */
/* https://github.com/httpwg/structured-field-tests/blob/main/display-string.json
*/

{
/* basic display string (ascii content) */
Expand All @@ -1576,6 +1577,33 @@ void test_sf_parser_dispstring(void) {
sf_parser_bytes_free();
}

{
/* all printable ascii */
sf_parser_bytes_init(&sfp, "%\" "
"!%22#$%25&'()*+,-./"
"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]"
"^_`abcdefghijklmnopqrstuvwxyz{|}~\"");

CU_ASSERT(0 == sf_parser_item(&sfp, &val));
CU_ASSERT(SF_TYPE_DISPSTRING == val.type);
CU_ASSERT(str_sf_vec_eq(" !%22#$%25&'()*+,-./"
"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]"
"^_`abcdefghijklmnopqrstuvwxyz{|}~",
&val.vec));

decoded.base = buf;
sf_pctdecode(&decoded, &val.vec);

CU_ASSERT(str_sf_vec_eq(" !\"#$%&'()*+,-./"
"0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"
"abcdefghijklmnopqrstuvwxyz{|}~",
&decoded));

CU_ASSERT(SF_ERR_EOF == sf_parser_item(&sfp, NULL));

sf_parser_bytes_free();
}

{
/* non-ascii display string (uppercase escaping) */
sf_parser_bytes_init(&sfp, "%\"f%C3%BC%C3%BC\"");
Expand Down Expand Up @@ -1630,6 +1658,24 @@ void test_sf_parser_dispstring(void) {
sf_parser_bytes_free();
}

{
/* unquoted display string */
sf_parser_bytes_init(&sfp, "%foo");

CU_ASSERT(SF_ERR_PARSE_ERROR == sf_parser_item(&sfp, &val));

sf_parser_bytes_free();
}

{
/* display string missing initial quote */
sf_parser_bytes_init(&sfp, "%foo\"");

CU_ASSERT(SF_ERR_PARSE_ERROR == sf_parser_item(&sfp, &val));

sf_parser_bytes_free();
}

{
/* unbalanced display string */
sf_parser_bytes_init(&sfp, "%\"foo");
Expand Down Expand Up @@ -1702,6 +1748,24 @@ void test_sf_parser_dispstring(void) {
sf_parser_bytes_free();
}

{
/* BOM in display string */
sf_parser_bytes_init(&sfp, "%\"BOM: %ef%bb%bf\"");

CU_ASSERT(0 == sf_parser_item(&sfp, &val));
CU_ASSERT(SF_TYPE_DISPSTRING == val.type);
CU_ASSERT(str_sf_vec_eq("BOM: %ef%bb%bf", &val.vec));

decoded.base = buf;
sf_pctdecode(&decoded, &val.vec);

CU_ASSERT(str_sf_vec_eq("BOM: \xef\xbb\xbf", &decoded));

CU_ASSERT(SF_ERR_EOF == sf_parser_item(&sfp, NULL));

sf_parser_bytes_free();
}

/* Additional tests */

{
Expand Down

0 comments on commit c36bc9a

Please sign in to comment.