"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/utils/test/js_normalizer_test.cc" between
snort3-3.1.36.0.tar.gz and snort3-3.1.38.0.tar.gz

About: Snort 3 is a network intrusion prevention and detection system (IDS/IPS) combining the benefits of signature, protocol and anomaly-based inspection.

js_normalizer_test.cc  (snort3-3.1.36.0):js_normalizer_test.cc  (snort3-3.1.38.0)
skipping to change at line 70 skipping to change at line 70
CHECK(!memcmp(dst, expected, act_len)); \ CHECK(!memcmp(dst, expected, act_len)); \
delete[] dst; delete[] dst;
#define VALIDATE_FAIL(src, expected, ret_code, ptr_offset) \ #define VALIDATE_FAIL(src, expected, ret_code, ptr_offset) \
CHECK(ret == ret_code); \ CHECK(ret == ret_code); \
CHECK((ptr - src) == ptr_offset); \ CHECK((ptr - src) == ptr_offset); \
CHECK(act_len == sizeof(expected) - 1); \ CHECK(act_len == sizeof(expected) - 1); \
CHECK(!memcmp(dst, expected, act_len)); \ CHECK(!memcmp(dst, expected, act_len)); \
delete[] dst; delete[] dst;
#define CHECK_OTAG(is_set) \
if (is_set) \
CHECK(norm.is_opening_tag_seen()); \
else \
CHECK(!norm.is_opening_tag_seen());
#define NORMALIZE_L(src, src_len, dst, dst_len, depth, ret, ptr, len) \ #define NORMALIZE_L(src, src_len, dst, dst_len, depth, ret, ptr, len) \
{ \ { \
JSIdentifierCtxStub ident_ctx; \ JSIdentifierCtxStub ident_ctx; \
JSNormalizer norm(ident_ctx, depth, max_template_nesting, max_bracket_de pth); \ JSNormalizer norm(ident_ctx, depth, max_template_nesting, max_bracket_de pth); \
ret = norm.normalize(src, src_len); \ ret = norm.normalize(src, src_len); \
ptr = norm.get_src_next(); \ ptr = norm.get_src_next(); \
len = norm.script_size(); \ len = norm.script_size(); \
const char* dptr = norm.get_script(); \ const char* dptr = norm.get_script(); \
REQUIRE(len == dst_len); \ REQUIRE(len == dst_len); \
memcpy(dst, dptr, dst_len); \ memcpy(dst, dptr, dst_len); \
skipping to change at line 1076 skipping to change at line 1082
"var a=b+ -c;"; "var a=b+ -c;";
// In the following cases: // In the following cases:
// a reading cursor will be after the literal // a reading cursor will be after the literal
// a malformed literal is not present in the output // a malformed literal is not present in the output
static const char syntax_cases_buf15[] = static const char syntax_cases_buf15[] =
"var invalid_str = 'abc\u2028 def' ;\n"; "var invalid_str = 'abc\u2028 def' ;\n";
static const char syntax_cases_expected15[] = static const char syntax_cases_expected15[] =
"var invalid_str='abc"; "var invalid_str='abc\u2028 def';";
static const char syntax_cases_buf16[] = static const char syntax_cases_buf16[] =
"var invalid_str = \"abc\n def\""; "var invalid_str = \"abc\n def\"";
static const char syntax_cases_expected16[] = static const char syntax_cases_expected16[] =
"var invalid_str=\"abc"; "var invalid_str=\"abc";
static const char syntax_cases_buf17[] = static const char syntax_cases_buf17[] =
"var invalid_str = 'abc\r def'"; "var invalid_str = 'abc\r def'";
skipping to change at line 1112 skipping to change at line 1118
static const char syntax_cases_buf20[] = static const char syntax_cases_buf20[] =
"var invalid_re = /abc\\\r\n def/"; "var invalid_re = /abc\\\r\n def/";
static const char syntax_cases_expected20[] = static const char syntax_cases_expected20[] =
"var invalid_re=/abc"; "var invalid_re=/abc";
static const char syntax_cases_buf21[] = static const char syntax_cases_buf21[] =
"var invalid_str = 'abc\u2029 def' ;\n\r"; "var invalid_str = 'abc\u2029 def' ;\n\r";
static const char syntax_cases_expected21[] = static const char syntax_cases_expected21[] =
"var invalid_str='abc"; "var invalid_str='abc\u2029 def';";
static const char syntax_cases_buf22[] = static const char syntax_cases_buf22[] =
"tag`template\n \\\\\\${ } \\\\${ a + ` template ${ 1 + c }` }`"; "tag`template\n \\\\\\${ } \\\\${ a + ` template ${ 1 + c }` }`";
static const char syntax_cases_expected22[] = static const char syntax_cases_expected22[] =
"tag `template\n \\\\\\${ } \\\\${a+` template ${1+c}`}`"; "tag `template\n \\\\\\${ } \\\\${a+` template ${1+c}`}`";
static const char syntax_cases_buf23[] = static const char syntax_cases_buf23[] =
"`${`${`${`${`${}`}`}`}`}`}"; "`${`${`${`${`${}`}`}`}`}`}";
skipping to change at line 1142 skipping to change at line 1148
"var b=/(((("; "var b=/((((";
static const char syntax_cases_buf25[] = static const char syntax_cases_buf25[] =
"return /regex0/.foo + /regex1/.bar ;" "return /regex0/.foo + /regex1/.bar ;"
"return /regex2/.baz * /regex3/.qux ;"; "return /regex2/.baz * /regex3/.qux ;";
static const char syntax_cases_expected25[] = static const char syntax_cases_expected25[] =
"return /regex0/.var_0000+/regex1/.var_0001;" "return /regex0/.var_0000+/regex1/.var_0001;"
"return /regex2/.var_0002*/regex3/.var_0003;"; "return /regex2/.var_0002*/regex3/.var_0003;";
static const char syntax_cases_buf26[] =
"var invalid_re = /abc \n def/ ;";
static const char syntax_cases_expected26[] =
"var invalid_re=/abc ";
TEST_CASE("syntax cases", "[JSNormalizer]") TEST_CASE("syntax cases", "[JSNormalizer]")
{ {
SECTION("variables") SECTION("variables")
{ {
NORMALIZE(syntax_cases_buf0); NORMALIZE(syntax_cases_buf0);
VALIDATE(syntax_cases_buf0, syntax_cases_expected0); VALIDATE(syntax_cases_buf0, syntax_cases_expected0);
} }
SECTION("operators") SECTION("operators")
{ {
NORMALIZE(syntax_cases_buf1); NORMALIZE(syntax_cases_buf1);
skipping to change at line 1219 skipping to change at line 1231
SECTION("regex after keyword") SECTION("regex after keyword")
{ {
NORMALIZE(syntax_cases_buf13); NORMALIZE(syntax_cases_buf13);
VALIDATE(syntax_cases_buf13, syntax_cases_expected13); VALIDATE(syntax_cases_buf13, syntax_cases_expected13);
} }
SECTION("white space between '+'<-->'++' and '-'<-->'--'") SECTION("white space between '+'<-->'++' and '-'<-->'--'")
{ {
NORMALIZE(syntax_cases_buf14); NORMALIZE(syntax_cases_buf14);
VALIDATE(syntax_cases_buf14, syntax_cases_expected14); VALIDATE(syntax_cases_buf14, syntax_cases_expected14);
} }
SECTION("LS within literal")
{
NORMALIZE(syntax_cases_buf15);
VALIDATE(syntax_cases_buf15, syntax_cases_expected15);
}
SECTION("PS within literal")
{
NORMALIZE(syntax_cases_buf21);
VALIDATE(syntax_cases_buf21, syntax_cases_expected21);
}
SECTION("template literals") SECTION("template literals")
{ {
NORMALIZE(syntax_cases_buf22); NORMALIZE(syntax_cases_buf22);
VALIDATE(syntax_cases_buf22, syntax_cases_expected22); VALIDATE(syntax_cases_buf22, syntax_cases_expected22);
} }
SECTION("regex after operator") SECTION("regex after operator")
{ {
NORMALIZE_S(syntax_cases_buf25, syntax_cases_expected25); NORMALIZE_S(syntax_cases_buf25, syntax_cases_expected25);
} }
} }
TEST_CASE("bad tokens", "[JSNormalizer]") TEST_CASE("bad tokens", "[JSNormalizer]")
{ {
SECTION("LS chars within literal")
{
NORMALIZE(syntax_cases_buf15);
VALIDATE_FAIL(syntax_cases_buf15, syntax_cases_expected15, JSTokenizer::
BAD_TOKEN, 25);
}
SECTION("PS chars within literal")
{
NORMALIZE(syntax_cases_buf21);
VALIDATE_FAIL(syntax_cases_buf21, syntax_cases_expected21, JSTokenizer::
BAD_TOKEN, 25);
}
SECTION("explicit LF within literal") SECTION("explicit LF within literal")
{ {
NORMALIZE(syntax_cases_buf16); NORMALIZE(syntax_cases_buf16);
VALIDATE_FAIL(syntax_cases_buf16, syntax_cases_expected16, JSTokenizer:: BAD_TOKEN, 23); VALIDATE_FAIL(syntax_cases_buf16, syntax_cases_expected16, JSTokenizer:: BAD_TOKEN, 23);
} }
SECTION("explicit CR within literal") SECTION("explicit CR within literal")
{ {
NORMALIZE(syntax_cases_buf17); NORMALIZE(syntax_cases_buf17);
VALIDATE_FAIL(syntax_cases_buf17, syntax_cases_expected17, JSTokenizer:: BAD_TOKEN, 23); VALIDATE_FAIL(syntax_cases_buf17, syntax_cases_expected17, JSTokenizer:: BAD_TOKEN, 23);
} }
skipping to change at line 1267 skipping to change at line 1279
SECTION("escaped LF within regex literal") SECTION("escaped LF within regex literal")
{ {
NORMALIZE(syntax_cases_buf19); NORMALIZE(syntax_cases_buf19);
VALIDATE_FAIL(syntax_cases_buf19, syntax_cases_expected19, JSTokenizer:: BAD_TOKEN, 23); VALIDATE_FAIL(syntax_cases_buf19, syntax_cases_expected19, JSTokenizer:: BAD_TOKEN, 23);
} }
SECTION("escaped CR-LF within regex literal") SECTION("escaped CR-LF within regex literal")
{ {
NORMALIZE(syntax_cases_buf20); NORMALIZE(syntax_cases_buf20);
VALIDATE_FAIL(syntax_cases_buf20, syntax_cases_expected20, JSTokenizer:: BAD_TOKEN, 23); VALIDATE_FAIL(syntax_cases_buf20, syntax_cases_expected20, JSTokenizer:: BAD_TOKEN, 23);
} }
SECTION("explicit LF within regex literal")
{
NORMALIZE(syntax_cases_buf26);
VALIDATE_FAIL(syntax_cases_buf26, syntax_cases_expected26, JSTokenizer::
BAD_TOKEN, 23);
}
} }
TEST_CASE("braces overflow", "[JSNormalizer]") TEST_CASE("braces overflow", "[JSNormalizer]")
{ {
SECTION("exceeding template literal limit") SECTION("exceeding template literal limit")
{ {
NORMALIZE(syntax_cases_buf23); NORMALIZE(syntax_cases_buf23);
VALIDATE_FAIL(syntax_cases_buf23, syntax_cases_expected23, VALIDATE_FAIL(syntax_cases_buf23, syntax_cases_expected23,
JSTokenizer::TEMPLATE_NESTING_OVERFLOW, 15); JSTokenizer::TEMPLATE_NESTING_OVERFLOW, 15);
} }
skipping to change at line 1674 skipping to change at line 1691
delete[] dst2; delete[] dst2;
} }
} }
static const char unexpected_tag_buf0[] = static const char unexpected_tag_buf0[] =
"var a = 1;\n" "var a = 1;\n"
"<script>\n" "<script>\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected0[] = static const char unexpected_tag_expected0[] =
"var a=1;"; "var a=1;<script>var b=2;";
static const char unexpected_tag_expected0_ext[] =
"var a=1;";
static const char unexpected_tag_buf1[] = static const char unexpected_tag_buf1[] =
"var a = 1;\n" "var a = 1;\n"
"<script type=application/javascript>\n" "<script type=application/javascript>\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected1[] = static const char unexpected_tag_expected1[] =
"var a=1;"; "var a=1;<script type=application/javascript>var b=2;";
static const char unexpected_tag_expected1_ext[] =
"var a=1;";
static const char unexpected_tag_buf2[] = static const char unexpected_tag_buf2[] =
"var a = 1;\n" "var a = 1;\n"
"var str = '<script> something';\n" "var str = '<script> something';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected2[] = static const char unexpected_tag_expected2[] =
"var a=1;var str='";
static const char unexpected_tag_expected2_ext[] =
"var a=1;var str='<script> something';var b=2;"; "var a=1;var str='<script> something';var b=2;";
static const char unexpected_tag_buf3[] = static const char unexpected_tag_buf3[] =
"var a = 1;\n" "var a = 1;\n"
"var str = 'something <script> something';\n" "var str = 'something <script> something';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected3[] = static const char unexpected_tag_expected3[] =
"var a=1;var str='something ";
static const char unexpected_tag_expected3_ext[] =
"var a=1;var str='something <script> something';var b=2;"; "var a=1;var str='something <script> something';var b=2;";
static const char unexpected_tag_buf4[] = static const char unexpected_tag_buf4[] =
"var a = 1;\n" "var a = 1;\n"
"var str = 'something <script>';\n" "var str = 'something <script>';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected4[] = static const char unexpected_tag_expected4[] =
"var a=1;var str='something ";
static const char unexpected_tag_expected4_ext[] =
"var a=1;var str='something <script>';var b=2;"; "var a=1;var str='something <script>';var b=2;";
static const char unexpected_tag_buf5[] = static const char unexpected_tag_buf5[] =
"var a = 1;\n" "var a = 1;\n"
"var str = '</script> something';\n" "var str = '</script> something';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected5[] = static const char unexpected_tag_expected5[] =
"var a=1;var str='"; "var a=1;var str='";
skipping to change at line 1762 skipping to change at line 1764
static const char unexpected_tag_expected7_ext[] = static const char unexpected_tag_expected7_ext[] =
"var a=1;var str='something </script>';var b=2;"; "var a=1;var str='something </script>';var b=2;";
static const char unexpected_tag_buf8[] = static const char unexpected_tag_buf8[] =
"var a = 1;\n" "var a = 1;\n"
"var str = 'something \\<script> something';\n" "var str = 'something \\<script> something';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected8[] = static const char unexpected_tag_expected8[] =
"var a=1;var str='something \\";
static const char unexpected_tag_expected8_ext[] =
"var a=1;var str='something \\<script> something';var b=2;"; "var a=1;var str='something \\<script> something';var b=2;";
static const char unexpected_tag_buf9[] = static const char unexpected_tag_buf9[] =
"var a = 1;\n" "var a = 1;\n"
"var str = 'something \\<\\/script\\> something';\n" "var str = 'something \\<\\/script\\> something';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected9[] = static const char unexpected_tag_expected9[] =
"var a=1;var str='something \\<\\/script\\> something';var b=2;"; "var a=1;var str='something \\<\\/script\\> something';var b=2;";
static const char unexpected_tag_expected9_ext[] = static const char unexpected_tag_expected9_ext[] =
"var a=1;var str='something \\<\\/script\\> something';var b=2;"; "var a=1;var str='something \\<\\/script\\> something';var b=2;";
static const char unexpected_tag_buf10[] = static const char unexpected_tag_buf10[] =
"var a = 1;\n" "var a = 1;\n"
"//<script> something\n" "//<script> something\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected10[] = static const char unexpected_tag_expected10[] =
"var a=1;";
static const char unexpected_tag_expected10_ext[] =
"var a=1;var b=2;"; "var a=1;var b=2;";
static const char unexpected_tag_buf11[] = static const char unexpected_tag_buf11[] =
"var a = 1;\n" "var a = 1;\n"
"//something <script> something\n" "//something <script> something\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected11[] = static const char unexpected_tag_expected11[] =
"var a=1;";
static const char unexpected_tag_expected11_ext[] =
"var a=1;var b=2;"; "var a=1;var b=2;";
static const char unexpected_tag_buf12[] = static const char unexpected_tag_buf12[] =
"var a = 1;\n" "var a = 1;\n"
"//something <script>\n" "//something <script>\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected12[] = static const char unexpected_tag_expected12[] =
"var a=1;";
static const char unexpected_tag_expected12_ext[] =
"var a=1;var b=2;"; "var a=1;var b=2;";
static const char unexpected_tag_buf13[] = static const char unexpected_tag_buf13[] =
"var a = 1;\n" "var a = 1;\n"
"/*<script> something*/\n" "/*<script> something*/\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected13[] = static const char unexpected_tag_expected13[] =
"var a=1;";
static const char unexpected_tag_expected13_ext[] =
"var a=1;var b=2;"; "var a=1;var b=2;";
static const char unexpected_tag_buf14[] = static const char unexpected_tag_buf14[] =
"var a = 1;\n" "var a = 1;\n"
"/*something <script> something*/\n" "/*something <script> something*/\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected14[] = static const char unexpected_tag_expected14[] =
"var a=1;";
static const char unexpected_tag_expected14_ext[] =
"var a=1;var b=2;"; "var a=1;var b=2;";
static const char unexpected_tag_buf15[] = static const char unexpected_tag_buf15[] =
"var a = 1;\n" "var a = 1;\n"
"/*something <script>*/\n" "/*something <script>*/\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected15[] = static const char unexpected_tag_expected15[] =
"var a=1;";
static const char unexpected_tag_expected15_ext[] =
"var a=1;var b=2;"; "var a=1;var b=2;";
static const char unexpected_tag_buf16[] = static const char unexpected_tag_buf16[] =
"var a = 1;\n" "var a = 1;\n"
"//</script> something\n" "//</script> something\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected16[] = static const char unexpected_tag_expected16[] =
"var a=1;"; "var a=1;";
skipping to change at line 1922 skipping to change at line 1903
"var a=1;var b=2;"; "var a=1;var b=2;";
static const char unexpected_tag_buf22[] = static const char unexpected_tag_buf22[] =
"var a = 1;\n" "var a = 1;\n"
"var str = 'script somescript /script something';\n" "var str = 'script somescript /script something';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected22[] = static const char unexpected_tag_expected22[] =
"var a=1;var str='script somescript /script something';var b=2;"; "var a=1;var str='script somescript /script something';var b=2;";
static const char unexpected_tag_expected22_ext[] =
"var a=1;var str='script somescript /script something';var b=2;";
static const char unexpected_tag_buf23[] = static const char unexpected_tag_buf23[] =
"var a = 1;\n" "var a = 1;\n"
"var str = 'script somescript /script something <script>';\n" "var str = 'script somescript /script something <script>';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected23[] = static const char unexpected_tag_expected23[] =
"var a=1;var str='script somescript /script something ";
static const char unexpected_tag_expected23_ext[] =
"var a=1;var str='script somescript /script something <script>';var b=2;"; "var a=1;var str='script somescript /script something <script>';var b=2;";
static const char unexpected_tag_buf24[] = static const char unexpected_tag_buf24[] =
"var a = 1;\n" "var a = 1;\n"
"var str = 'something <sCrIpT>';\n" "var str = 'something <sCrIpT>';\n"
"var b = 2;\r\n"; "var b = 2;\r\n";
static const char unexpected_tag_expected24[] = static const char unexpected_tag_expected24[] =
"var a=1;var str='something ";
static const char unexpected_tag_expected24_ext[] =
"var a=1;var str='something <sCrIpT>';var b=2;"; "var a=1;var str='something <sCrIpT>';var b=2;";
static const char unexpected_tag_buf25[] =
"var template = ` <script> ` ;";
static const char unexpected_tag_expected25[] =
"var template=` <script> `;";
static const char unexpected_tag_buf26[] =
"var regex = / <script> / ;";
static const char unexpected_tag_expected26[] =
"var regex=/ <script> /;";
TEST_CASE("nested script tags", "[JSNormalizer]") TEST_CASE("nested script tags", "[JSNormalizer]")
{ {
SECTION("explicit open tag - simple") SECTION("explicit open tag - simple")
{ {
NORMALIZE(unexpected_tag_buf0); NORMALIZE(unexpected_tag_buf0);
VALIDATE_FAIL(unexpected_tag_buf0, unexpected_tag_expected0, JSTokenizer VALIDATE(unexpected_tag_buf0, unexpected_tag_expected0);
::OPENING_TAG, 19); CHECK_OTAG(true);
} }
SECTION("explicit open tag - complex") SECTION("explicit open tag - complex")
{ {
NORMALIZE(unexpected_tag_buf1); NORMALIZE(unexpected_tag_buf1);
VALIDATE_FAIL(unexpected_tag_buf1, unexpected_tag_expected1, JSTokenizer VALIDATE(unexpected_tag_buf1, unexpected_tag_expected1);
::OPENING_TAG, 19); CHECK_OTAG(true);
} }
SECTION("open tag within literal - start") SECTION("open tag within literal - start")
{ {
NORMALIZE(unexpected_tag_buf2); NORMALIZE(unexpected_tag_buf2);
VALIDATE_FAIL(unexpected_tag_buf2, unexpected_tag_expected2, JSTokenizer VALIDATE(unexpected_tag_buf2, unexpected_tag_expected2);
::OPENING_TAG, 30); CHECK_OTAG(true);
} }
SECTION("open tag within literal - mid") SECTION("open tag within literal - mid")
{ {
NORMALIZE(unexpected_tag_buf3); NORMALIZE(unexpected_tag_buf3);
VALIDATE_FAIL(unexpected_tag_buf3, unexpected_tag_expected3, JSTokenizer VALIDATE(unexpected_tag_buf3, unexpected_tag_expected3);
::OPENING_TAG, 40); CHECK_OTAG(true);
} }
SECTION("open tag within literal - end") SECTION("open tag within literal - end")
{ {
NORMALIZE(unexpected_tag_buf4); NORMALIZE(unexpected_tag_buf4);
VALIDATE_FAIL(unexpected_tag_buf4, unexpected_tag_expected4, JSTokenizer VALIDATE(unexpected_tag_buf4, unexpected_tag_expected4);
::OPENING_TAG, 40); CHECK_OTAG(true);
} }
SECTION("close tag within literal - start") SECTION("close tag within literal - start")
{ {
NORMALIZE(unexpected_tag_buf5); NORMALIZE(unexpected_tag_buf5);
VALIDATE_FAIL(unexpected_tag_buf5, unexpected_tag_expected5, JSTokenizer ::CLOSING_TAG, 31); VALIDATE_FAIL(unexpected_tag_buf5, unexpected_tag_expected5, JSTokenizer ::CLOSING_TAG, 31);
} }
SECTION("close tag within literal - mid") SECTION("close tag within literal - mid")
{ {
NORMALIZE(unexpected_tag_buf6); NORMALIZE(unexpected_tag_buf6);
VALIDATE_FAIL(unexpected_tag_buf6, unexpected_tag_expected6, JSTokenizer ::CLOSING_TAG, 41); VALIDATE_FAIL(unexpected_tag_buf6, unexpected_tag_expected6, JSTokenizer ::CLOSING_TAG, 41);
} }
SECTION("close tag within literal - end") SECTION("close tag within literal - end")
{ {
NORMALIZE(unexpected_tag_buf7); NORMALIZE(unexpected_tag_buf7);
VALIDATE_FAIL(unexpected_tag_buf7, unexpected_tag_expected7, JSTokenizer ::CLOSING_TAG, 41); VALIDATE_FAIL(unexpected_tag_buf7, unexpected_tag_expected7, JSTokenizer ::CLOSING_TAG, 41);
} }
SECTION("open tag within literal - escaped") SECTION("open tag within literal - escaped")
{ {
NORMALIZE(unexpected_tag_buf8); NORMALIZE(unexpected_tag_buf8);
VALIDATE_FAIL(unexpected_tag_buf8, unexpected_tag_expected8, JSTokenizer VALIDATE(unexpected_tag_buf8, unexpected_tag_expected8);
::OPENING_TAG, 41); CHECK_OTAG(true);
} }
SECTION("close tag within literal - escaped") SECTION("close tag within literal - escaped")
{ {
NORMALIZE(unexpected_tag_buf9); NORMALIZE(unexpected_tag_buf9);
VALIDATE(unexpected_tag_buf9, unexpected_tag_expected9); VALIDATE(unexpected_tag_buf9, unexpected_tag_expected9);
} }
SECTION("open tag within single-line comment - start") SECTION("open tag within single-line comment - start")
{ {
NORMALIZE(unexpected_tag_buf10); NORMALIZE(unexpected_tag_buf10);
VALIDATE_FAIL(unexpected_tag_buf10, unexpected_tag_expected10, JSTokeniz VALIDATE(unexpected_tag_buf10, unexpected_tag_expected10);
er::OPENING_TAG, 20); CHECK_OTAG(true);
} }
SECTION("open tag within single-line comment - mid") SECTION("open tag within single-line comment - mid")
{ {
NORMALIZE(unexpected_tag_buf11); NORMALIZE(unexpected_tag_buf11);
VALIDATE_FAIL(unexpected_tag_buf11, unexpected_tag_expected11, JSTokeniz VALIDATE(unexpected_tag_buf11, unexpected_tag_expected11);
er::OPENING_TAG, 30); CHECK_OTAG(true);
} }
SECTION("open tag within single-line comment - end") SECTION("open tag within single-line comment - end")
{ {
NORMALIZE(unexpected_tag_buf12); NORMALIZE(unexpected_tag_buf12);
VALIDATE_FAIL(unexpected_tag_buf12, unexpected_tag_expected12, JSTokeniz VALIDATE(unexpected_tag_buf12, unexpected_tag_expected12);
er::OPENING_TAG, 30); CHECK_OTAG(true);
} }
SECTION("open tag within multi-line comment - start") SECTION("open tag within multi-line comment - start")
{ {
NORMALIZE(unexpected_tag_buf13); NORMALIZE(unexpected_tag_buf13);
VALIDATE_FAIL(unexpected_tag_buf13, unexpected_tag_expected13, JSTokeniz VALIDATE(unexpected_tag_buf13, unexpected_tag_expected13);
er::OPENING_TAG, 20); CHECK_OTAG(true);
} }
SECTION("open tag within multi-line comment - mid") SECTION("open tag within multi-line comment - mid")
{ {
NORMALIZE(unexpected_tag_buf14); NORMALIZE(unexpected_tag_buf14);
VALIDATE_FAIL(unexpected_tag_buf14, unexpected_tag_expected14, JSTokeniz VALIDATE(unexpected_tag_buf14, unexpected_tag_expected14);
er::OPENING_TAG, 30); CHECK_OTAG(true);
} }
SECTION("open tag within multi-line comment - end") SECTION("open tag within multi-line comment - end")
{ {
NORMALIZE(unexpected_tag_buf15); NORMALIZE(unexpected_tag_buf15);
VALIDATE_FAIL(unexpected_tag_buf15, unexpected_tag_expected15, JSTokeniz VALIDATE(unexpected_tag_buf15, unexpected_tag_expected15);
er::OPENING_TAG, 30); CHECK_OTAG(true);
} }
SECTION("close tag within single-line comment - start") SECTION("close tag within single-line comment - start")
{ {
NORMALIZE(unexpected_tag_buf16); NORMALIZE(unexpected_tag_buf16);
VALIDATE_FAIL(unexpected_tag_buf16, unexpected_tag_expected16, JSTokeniz er::SCRIPT_ENDED, 22); VALIDATE_FAIL(unexpected_tag_buf16, unexpected_tag_expected16, JSTokeniz er::SCRIPT_ENDED, 22);
} }
SECTION("close tag within single-line comment - mid") SECTION("close tag within single-line comment - mid")
{ {
NORMALIZE(unexpected_tag_buf17); NORMALIZE(unexpected_tag_buf17);
VALIDATE_FAIL(unexpected_tag_buf17, unexpected_tag_expected17, JSTokeniz er::SCRIPT_ENDED, 34); VALIDATE_FAIL(unexpected_tag_buf17, unexpected_tag_expected17, JSTokeniz er::SCRIPT_ENDED, 34);
skipping to change at line 2067 skipping to change at line 2063
VALIDATE_FAIL(unexpected_tag_buf21, unexpected_tag_expected21, JSTokeniz er::CLOSING_TAG, 32); VALIDATE_FAIL(unexpected_tag_buf21, unexpected_tag_expected21, JSTokeniz er::CLOSING_TAG, 32);
} }
SECTION("multiple patterns - not matched") SECTION("multiple patterns - not matched")
{ {
NORMALIZE(unexpected_tag_buf22); NORMALIZE(unexpected_tag_buf22);
VALIDATE(unexpected_tag_buf22, unexpected_tag_expected22); VALIDATE(unexpected_tag_buf22, unexpected_tag_expected22);
} }
SECTION("multiple patterns - matched") SECTION("multiple patterns - matched")
{ {
NORMALIZE(unexpected_tag_buf23); NORMALIZE(unexpected_tag_buf23);
VALIDATE_FAIL(unexpected_tag_buf23, unexpected_tag_expected23, JSTokeniz VALIDATE(unexpected_tag_buf23, unexpected_tag_expected23);
er::OPENING_TAG, 66); CHECK_OTAG(true);
} }
SECTION("mixed lower and upper case") SECTION("mixed lower and upper case")
{ {
NORMALIZE(unexpected_tag_buf24); NORMALIZE(unexpected_tag_buf24);
VALIDATE_FAIL(unexpected_tag_buf24, unexpected_tag_expected24, JSTokeniz VALIDATE(unexpected_tag_buf24, unexpected_tag_expected24);
er::OPENING_TAG, 40); CHECK_OTAG(true);
}
SECTION("opening tag within template literal")
{
NORMALIZE(unexpected_tag_buf25);
VALIDATE(unexpected_tag_buf25, unexpected_tag_expected25);
CHECK_OTAG(true);
}
SECTION("opening tag within regex literal")
{
NORMALIZE(unexpected_tag_buf26);
VALIDATE(unexpected_tag_buf26, unexpected_tag_expected26);
CHECK_OTAG(true);
} }
} }
TEST_CASE("opening tag sequence", "[JSNormalizer]") TEST_CASE("opening tag sequence", "[JSNormalizer]")
{ {
SECTION("incomplete") SECTION("incomplete")
{ {
const char src[] = "<script"; const char src[] = "<script";
const char exp[] = "<script"; const char exp[] = "<script";
NORMALIZE(src); NORMALIZE(src);
VALIDATE(src, exp); VALIDATE(src, exp);
CHECK_OTAG(false);
} }
SECTION("valid 1") SECTION("valid 1")
{ {
const char src[] = "<scripts"; const char src[] = "<scripts";
const char exp[] = "<scripts"; const char exp[] = "<scripts";
NORMALIZE(src); NORMALIZE(src);
VALIDATE(src, exp); VALIDATE(src, exp);
CHECK_OTAG(false);
} }
SECTION("valid 2") SECTION("valid 2")
{ {
const char src[] = "<script."; const char src[] = "<script.";
const char exp[] = "<script."; const char exp[] = "<script.";
NORMALIZE(src); NORMALIZE(src);
VALIDATE(src, exp); VALIDATE(src, exp);
CHECK_OTAG(false);
} }
SECTION("tabulation") SECTION("tabulation")
{ {
const char src[] = "<script\x9"; const char src[] = "<script\x9";
const char exp[] = ""; const char exp[] = "<script";
NORMALIZE(src); NORMALIZE(src);
VALIDATE_FAIL(src, exp, JSTokenizer::OPENING_TAG, 8); VALIDATE(src, exp);
CHECK_OTAG(true);
} }
SECTION("line feed") SECTION("line feed")
{ {
const char src[] = "<script\xA"; const char src[] = "<script\xA";
const char exp[] = ""; const char exp[] = "<script";
NORMALIZE(src); NORMALIZE(src);
VALIDATE_FAIL(src, exp, JSTokenizer::OPENING_TAG, 8); VALIDATE(src, exp);
CHECK_OTAG(true);
} }
SECTION("form feed") SECTION("form feed")
{ {
const char src[] = "<script\xC"; const char src[] = "<script\xC";
const char exp[] = ""; const char exp[] = "<script";
NORMALIZE(src); NORMALIZE(src);
VALIDATE_FAIL(src, exp, JSTokenizer::OPENING_TAG, 8); VALIDATE(src, exp);
CHECK_OTAG(true);
} }
SECTION("space") SECTION("space")
{ {
const char src[] = "<script\x20"; const char src[] = "<script\x20";
const char exp[] = ""; const char exp[] = "<script";
NORMALIZE(src); NORMALIZE(src);
VALIDATE_FAIL(src, exp, JSTokenizer::OPENING_TAG, 8); VALIDATE(src, exp);
CHECK_OTAG(true);
} }
SECTION("solidus") SECTION("solidus")
{ {
const char src[] = "<script\x2F"; const char src[] = "<script\x2F";
const char exp[] = ""; const char exp[] = "<script\x2F";
NORMALIZE(src); NORMALIZE(src);
VALIDATE_FAIL(src, exp, JSTokenizer::OPENING_TAG, 8); VALIDATE(src, exp);
CHECK_OTAG(true);
} }
SECTION("greater than") SECTION("greater than")
{ {
const char src[] = "<script\x3E"; const char src[] = "<script\x3E";
const char exp[] = ""; const char exp[] = "<script\x3E";
NORMALIZE(src); NORMALIZE(src);
VALIDATE_FAIL(src, exp, JSTokenizer::OPENING_TAG, 8); VALIDATE(src, exp);
CHECK_OTAG(true);
} }
} }
TEST_CASE("nested script tags in an external script", "[JSNormalizer]") TEST_CASE("nested script tags in an external script", "[JSNormalizer]")
{ {
SECTION("explicit open tag - simple") SECTION("explicit open tag - simple")
{ {
NORMALIZE_EXT(unexpected_tag_buf0); NORMALIZE_EXT(unexpected_tag_buf0);
VALIDATE_FAIL(unexpected_tag_buf0, unexpected_tag_expected0_ext, JSToken VALIDATE(unexpected_tag_buf0, unexpected_tag_expected0);
izer::OPENING_TAG, 19); CHECK_OTAG(false);
} }
SECTION("explicit open tag - complex") SECTION("explicit open tag - complex")
{ {
NORMALIZE_EXT(unexpected_tag_buf1); NORMALIZE_EXT(unexpected_tag_buf1);
VALIDATE_FAIL(unexpected_tag_buf1, unexpected_tag_expected1_ext, JSToken VALIDATE(unexpected_tag_buf1, unexpected_tag_expected1);
izer::OPENING_TAG, 19); CHECK_OTAG(false);
} }
SECTION("open tag within literal - start") SECTION("open tag within literal - start")
{ {
NORMALIZE_EXT(unexpected_tag_buf2); NORMALIZE_EXT(unexpected_tag_buf2);
VALIDATE(unexpected_tag_buf2, unexpected_tag_expected2_ext); VALIDATE(unexpected_tag_buf2, unexpected_tag_expected2);
CHECK_OTAG(false);
} }
SECTION("open tag within literal - mid") SECTION("open tag within literal - mid")
{ {
NORMALIZE_EXT(unexpected_tag_buf3); NORMALIZE_EXT(unexpected_tag_buf3);
VALIDATE(unexpected_tag_buf3, unexpected_tag_expected3_ext); VALIDATE(unexpected_tag_buf3, unexpected_tag_expected3);
CHECK_OTAG(false);
} }
SECTION("open tag within literal - end") SECTION("open tag within literal - end")
{ {
NORMALIZE_EXT(unexpected_tag_buf4); NORMALIZE_EXT(unexpected_tag_buf4);
VALIDATE(unexpected_tag_buf4, unexpected_tag_expected4_ext); VALIDATE(unexpected_tag_buf4, unexpected_tag_expected4);
CHECK_OTAG(false);
} }
SECTION("close tag within literal - start") SECTION("close tag within literal - start")
{ {
NORMALIZE_EXT(unexpected_tag_buf5); NORMALIZE_EXT(unexpected_tag_buf5);
VALIDATE(unexpected_tag_buf5, unexpected_tag_expected5_ext); VALIDATE(unexpected_tag_buf5, unexpected_tag_expected5_ext);
} }
SECTION("close tag within literal - mid") SECTION("close tag within literal - mid")
{ {
NORMALIZE_EXT(unexpected_tag_buf6); NORMALIZE_EXT(unexpected_tag_buf6);
VALIDATE(unexpected_tag_buf6, unexpected_tag_expected6_ext); VALIDATE(unexpected_tag_buf6, unexpected_tag_expected6_ext);
} }
SECTION("close tag within literal - end") SECTION("close tag within literal - end")
{ {
NORMALIZE_EXT(unexpected_tag_buf7); NORMALIZE_EXT(unexpected_tag_buf7);
VALIDATE(unexpected_tag_buf7, unexpected_tag_expected7_ext); VALIDATE(unexpected_tag_buf7, unexpected_tag_expected7_ext);
} }
SECTION("open tag within literal - escaped") SECTION("open tag within literal - escaped")
{ {
NORMALIZE_EXT(unexpected_tag_buf8); NORMALIZE_EXT(unexpected_tag_buf8);
VALIDATE(unexpected_tag_buf8, unexpected_tag_expected8_ext); VALIDATE(unexpected_tag_buf8, unexpected_tag_expected8);
CHECK_OTAG(false);
} }
SECTION("close tag within literal - escaped") SECTION("close tag within literal - escaped")
{ {
NORMALIZE_EXT(unexpected_tag_buf9); NORMALIZE_EXT(unexpected_tag_buf9);
VALIDATE(unexpected_tag_buf9, unexpected_tag_expected9_ext); VALIDATE(unexpected_tag_buf9, unexpected_tag_expected9_ext);
} }
SECTION("open tag within single-line comment - start") SECTION("open tag within single-line comment - start")
{ {
NORMALIZE_EXT(unexpected_tag_buf10); NORMALIZE_EXT(unexpected_tag_buf10);
VALIDATE(unexpected_tag_buf10, unexpected_tag_expected10_ext); VALIDATE(unexpected_tag_buf10, unexpected_tag_expected10);
CHECK_OTAG(false);
} }
SECTION("open tag within single-line comment - mid") SECTION("open tag within single-line comment - mid")
{ {
NORMALIZE_EXT(unexpected_tag_buf11); NORMALIZE_EXT(unexpected_tag_buf11);
VALIDATE(unexpected_tag_buf11, unexpected_tag_expected11_ext); VALIDATE(unexpected_tag_buf11, unexpected_tag_expected11);
CHECK_OTAG(false);
} }
SECTION("open tag within single-line comment - end") SECTION("open tag within single-line comment - end")
{ {
NORMALIZE_EXT(unexpected_tag_buf12); NORMALIZE_EXT(unexpected_tag_buf12);
VALIDATE(unexpected_tag_buf12, unexpected_tag_expected12_ext); VALIDATE(unexpected_tag_buf12, unexpected_tag_expected12);
CHECK_OTAG(false);
} }
SECTION("open tag within multi-line comment - start") SECTION("open tag within multi-line comment - start")
{ {
NORMALIZE_EXT(unexpected_tag_buf13); NORMALIZE_EXT(unexpected_tag_buf13);
VALIDATE(unexpected_tag_buf13, unexpected_tag_expected13_ext); VALIDATE(unexpected_tag_buf13, unexpected_tag_expected13);
CHECK_OTAG(false);
} }
SECTION("open tag within multi-line comment - mid") SECTION("open tag within multi-line comment - mid")
{ {
NORMALIZE_EXT(unexpected_tag_buf14); NORMALIZE_EXT(unexpected_tag_buf14);
VALIDATE(unexpected_tag_buf14, unexpected_tag_expected14_ext); VALIDATE(unexpected_tag_buf14, unexpected_tag_expected14);
CHECK_OTAG(false);
} }
SECTION("open tag within multi-line comment - end") SECTION("open tag within multi-line comment - end")
{ {
NORMALIZE_EXT(unexpected_tag_buf15); NORMALIZE_EXT(unexpected_tag_buf15);
VALIDATE(unexpected_tag_buf15, unexpected_tag_expected15_ext); VALIDATE(unexpected_tag_buf15, unexpected_tag_expected15);
CHECK_OTAG(false);
} }
SECTION("close tag within single-line comment - start") SECTION("close tag within single-line comment - start")
{ {
NORMALIZE_EXT(unexpected_tag_buf16); NORMALIZE_EXT(unexpected_tag_buf16);
VALIDATE(unexpected_tag_buf16, unexpected_tag_expected16_ext); VALIDATE(unexpected_tag_buf16, unexpected_tag_expected16_ext);
} }
SECTION("close tag within single-line comment - mid") SECTION("close tag within single-line comment - mid")
{ {
NORMALIZE_EXT(unexpected_tag_buf17); NORMALIZE_EXT(unexpected_tag_buf17);
VALIDATE(unexpected_tag_buf17, unexpected_tag_expected17_ext); VALIDATE(unexpected_tag_buf17, unexpected_tag_expected17_ext);
skipping to change at line 2267 skipping to change at line 2298
VALIDATE(unexpected_tag_buf20, unexpected_tag_expected20_ext); VALIDATE(unexpected_tag_buf20, unexpected_tag_expected20_ext);
} }
SECTION("close tag within multi-line comment - end") SECTION("close tag within multi-line comment - end")
{ {
NORMALIZE_EXT(unexpected_tag_buf21); NORMALIZE_EXT(unexpected_tag_buf21);
VALIDATE(unexpected_tag_buf21, unexpected_tag_expected21_ext); VALIDATE(unexpected_tag_buf21, unexpected_tag_expected21_ext);
} }
SECTION("multiple patterns - not matched") SECTION("multiple patterns - not matched")
{ {
NORMALIZE_EXT(unexpected_tag_buf22); NORMALIZE_EXT(unexpected_tag_buf22);
VALIDATE(unexpected_tag_buf22, unexpected_tag_expected22_ext); VALIDATE(unexpected_tag_buf22, unexpected_tag_expected22);
} }
SECTION("multiple patterns - matched") SECTION("multiple patterns - matched")
{ {
NORMALIZE_EXT(unexpected_tag_buf23); NORMALIZE_EXT(unexpected_tag_buf23);
VALIDATE(unexpected_tag_buf23, unexpected_tag_expected23_ext); VALIDATE(unexpected_tag_buf23, unexpected_tag_expected23);
CHECK_OTAG(false);
} }
SECTION("mixed lower and upper case") SECTION("mixed lower and upper case")
{ {
NORMALIZE_EXT(unexpected_tag_buf24); NORMALIZE_EXT(unexpected_tag_buf24);
VALIDATE(unexpected_tag_buf24, unexpected_tag_expected24_ext); VALIDATE(unexpected_tag_buf24, unexpected_tag_expected24);
CHECK_OTAG(false);
}
SECTION("opening tag within template literal")
{
NORMALIZE_EXT(unexpected_tag_buf25);
VALIDATE(unexpected_tag_buf25, unexpected_tag_expected25);
CHECK_OTAG(false);
}
SECTION("opening tag within regex literal")
{
NORMALIZE_EXT(unexpected_tag_buf26);
VALIDATE(unexpected_tag_buf26, unexpected_tag_expected26);
CHECK_OTAG(false);
} }
} }
TEST_CASE("split between tokens", "[JSNormalizer]") TEST_CASE("split between tokens", "[JSNormalizer]")
{ {
SECTION("operator string") SECTION("operator string")
{ {
const char dat1[] = "var s = "; const char dat1[] = "var s = ";
const char dat2[] = "'string';"; const char dat2[] = "'string';";
const char exp1[] = "var s="; const char exp1[] = "var s=";
skipping to change at line 2329 skipping to change at line 2374
const char dat2[] = "a = "; const char dat2[] = "a = ";
const char dat3[] = "b ;"; const char dat3[] = "b ;";
const char exp1[] = "var"; const char exp1[] = "var";
const char exp2[] = " a="; const char exp2[] = " a=";
const char exp3[] = "b;"; const char exp3[] = "b;";
const char exp[] = "var a=b;"; const char exp[] = "var a=b;";
NORMALIZE_3(dat1, dat2, dat3, exp1, exp2, exp3); NORMALIZE_3(dat1, dat2, dat3, exp1, exp2, exp3);
NORM_COMBINED_3(dat1, dat2, dat3, exp); NORM_COMBINED_3(dat1, dat2, dat3, exp);
} }
SECTION("complete open tag - identifier")
{
const char dat1[] = " ( a <script> ";
const char dat2[] = " b ) ";
const char exp1[] = "(a<script>";
const char exp2[] = "b)";
const char exp[] = "(a<script>b)";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
SECTION("incomplete open tag - identifier")
{
const char dat1[] = " <script ";
const char dat2[] = " a ; ";
const char exp1[] = "<script";
const char exp2[] = " a;";
const char exp[] = "<script a;";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
SECTION("incomplete open tag - operator")
{
const char dat1[] = " ( a <script ";
const char dat2[] = " ) ";
const char exp1[] = "(a<script";
const char exp2[] = ")";
const char exp[] = "(a<script)";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
SECTION("identifier - complete open tag")
{
const char dat1[] = " ( a ";
const char dat2[] = " <script> b ) ";
const char exp1[] = "(a";
const char exp2[] = "<script>b)";
const char exp[] = "(a<script>b)";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
SECTION("identifier - incomplete open tag")
{
const char dat1[] = " ( a ";
const char dat2[] = " <script ) ";
const char exp1[] = "(a";
const char exp2[] = "<script)";
const char exp[] = "(a<script)";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
SECTION("operator - incomplete open tag")
{
const char dat1[] = " ( a < ";
const char dat2[] = " <script ) ";
const char exp1[] = "(a<";
const char exp2[] = "<script)";
const char exp[] = "(a<<script)";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
SECTION("identifier - incomplete open tag as a comparison")
{
const char dat1[] = " ( a < ";
const char dat2[] = " script ) ";
const char exp1[] = "(a<";
const char exp2[] = "script)";
const char exp[] = "(a<script)";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
SECTION("identifier - complete open tag as a comparison")
{
const char dat1[] = " ( a <";
const char dat2[] = "script ) ";
const char exp1[] = "(a<";
const char exp2[] = "<script)";
const char exp[] = "(a<script)";
NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_2(dat1, dat2, exp);
}
} }
TEST_CASE("split in comments", "[JSNormalizer]") TEST_CASE("split in comments", "[JSNormalizer]")
{ {
SECTION("/ /") SECTION("/ /")
{ {
const char dat1[] = "/"; const char dat1[] = "/";
const char dat2[] = "/comment\n"; const char dat2[] = "/comment\n";
const char exp1[] = "/"; const char exp1[] = "/";
const char exp2[] = ""; const char exp2[] = "";
skipping to change at line 2480 skipping to change at line 2613
} }
} }
TEST_CASE("split in opening tag", "[JSNormalizer]") TEST_CASE("split in opening tag", "[JSNormalizer]")
{ {
SECTION("< script") SECTION("< script")
{ {
const char dat1[] = "<"; const char dat1[] = "<";
const char dat2[] = "script>"; const char dat2[] = "script>";
const char exp1[] = "<"; const char exp1[] = "<";
const char exp2[] = ""; const char exp2[] = "<script>";
const char exp[] = ""; const char exp[] = "<script>";
NORM_BAD_2(dat1, dat2, exp1, exp2, JSTokenizer::OPENING_TAG); NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_BAD_2(dat1, dat2, exp, JSTokenizer::OPENING_TAG); NORM_COMBINED_2(dat1, dat2, exp);
} }
SECTION("str='<s cript'") SECTION("str='<s cript'")
{ {
const char dat1[] = "var str ='<s"; const char dat1[] = "var str ='<s";
const char dat2[] = "cript>';"; const char dat2[] = "cript>';";
const char exp1[] = "var str='<s"; const char exp1[] = "var str='<s";
const char exp2[] = ""; const char exp2[] = "<script>';";
const char exp[] = "var str='"; const char exp[] = "var str='<script>';";
NORM_BAD_2(dat1, dat2, exp1, exp2, JSTokenizer::OPENING_TAG); NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_BAD_2(dat1, dat2, exp, JSTokenizer::OPENING_TAG); NORM_COMBINED_2(dat1, dat2, exp);
} }
SECTION("str='<scrip t'") SECTION("str='<scrip t'")
{ {
const char dat1[] = "var str ='<scrip"; const char dat1[] = "var str ='<scrip";
const char dat2[] = "t>';"; const char dat2[] = "t>';";
const char exp1[] = "var str='<scrip"; const char exp1[] = "var str='<scrip";
const char exp2[] = ""; const char exp2[] = "<script>';";
const char exp[] = "var str='"; const char exp[] = "var str='<script>';";
NORM_BAD_2(dat1, dat2, exp1, exp2, JSTokenizer::OPENING_TAG); NORMALIZE_2(dat1, dat2, exp1, exp2);
NORM_COMBINED_BAD_2(dat1, dat2, exp, JSTokenizer::OPENING_TAG); NORM_COMBINED_2(dat1, dat2, exp);
} }
SECTION("< scr ipt") SECTION("< scr ipt")
{ {
const char dat1[] = "<"; const char dat1[] = "<";
const char dat2[] = "scr"; const char dat2[] = "scr";
const char dat3[] = "ipt>"; const char dat3[] = "ipt>";
const char exp1[] = "<"; const char exp1[] = "<";
const char exp2[] = "scr"; const char exp2[] = "scr";
const char exp3[] = ""; const char exp3[] = "<script>";
const char exp[] = ""; const char exp[] = "<script>";
NORM_BAD_3(dat1, dat2, dat3, exp1, exp2, exp3, JSTokenizer::OPENING_TAG) NORMALIZE_3(dat1, dat2, dat3, exp1, exp2, exp3);
; NORM_COMBINED_3(dat1, dat2, dat3, exp);
NORM_COMBINED_BAD_3(dat1, dat2, dat3, exp, JSTokenizer::OPENING_TAG);
} }
SECTION("str='<sc rip t'") SECTION("str='<sc rip t'")
{ {
const char dat1[] = "var str =\"<sc"; const char dat1[] = "var str =\"<sc";
const char dat2[] = "rip"; const char dat2[] = "rip";
const char dat3[] = "t>\";"; const char dat3[] = "t>\";";
const char exp1[] = "var str=\"<sc"; const char exp1[] = "var str=\"<sc";
const char exp2[] = "scrip"; const char exp2[] = "scrip";
const char exp3[] = ""; const char exp3[] = "<script>\";";
const char exp[] = "var str=\""; const char exp[] = "var str=\"<script>\";";
NORM_BAD_3(dat1, dat2, dat3, exp1, exp2, exp3, JSTokenizer::OPENING_TAG) NORMALIZE_3(dat1, dat2, dat3, exp1, exp2, exp3);
; NORM_COMBINED_3(dat1, dat2, dat3, exp);
NORM_COMBINED_BAD_3(dat1, dat2, dat3, exp, JSTokenizer::OPENING_TAG);
} }
} }
TEST_CASE("split in closing tag", "[JSNormalizer]") TEST_CASE("split in closing tag", "[JSNormalizer]")
{ {
SECTION("< /script>") SECTION("< /script>")
{ {
const char dat1[] = "<"; const char dat1[] = "<";
const char dat2[] = "/script>"; const char dat2[] = "/script>";
const char exp1[] = "<"; const char exp1[] = "<";
 End of changes. 78 change blocks. 
140 lines changed or deleted 254 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)