From ff436e3f26b93d3c6a71b650ca917643fc5e4d54 Mon Sep 17 00:00:00 2001 From: fengweihao Date: Wed, 20 Nov 2024 10:03:12 +0800 Subject: TSG-23793 Fixed the issue where comments in the HTML page containing or tags would cause the inserted script to fail --- .../tsg-http/test/test_pattern_replace.cpp | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'plugin/business/tsg-http/test/test_pattern_replace.cpp') diff --git a/plugin/business/tsg-http/test/test_pattern_replace.cpp b/plugin/business/tsg-http/test/test_pattern_replace.cpp index 0756313..e9f2a59 100644 --- a/plugin/business/tsg-http/test/test_pattern_replace.cpp +++ b/plugin/business/tsg-http/test/test_pattern_replace.cpp @@ -7,7 +7,6 @@ #include #include - TEST(PatternReplace, Grouping1) { const char* find="(?John)|(?李梅梅)|(?Jake)"; @@ -305,9 +304,38 @@ TEST(PatternInsert, BeforeBody) free(output); } -int main(int argc, char ** argv) +TEST(PatternInsert, HtmlCommentsContain) +{ + char input[]=""; + const char* custom = "alert(\"Insert\");"; + char *output=NULL; + size_t output_sz=0, input_sz = strlen(input) - 5; + + output_sz = simple_insert(input, input_sz, "before-page-load", custom, "js", &output); + printf("output =%s\n", output); + + EXPECT_TRUE(output_sz>0); + EXPECT_TRUE(NULL!=strstr(output, custom)); + free(output); +} + +TEST(PatternInsert, HtmlNoCommentsContain) { + char input[]=""; + const char* custom = "alert(\"Insert\");"; + char *output=NULL; + size_t output_sz=0, input_sz = strlen(input); + + output_sz = simple_insert(input, input_sz, "before-page-load", custom, "js", &output); + printf("output =%s\n", output); + EXPECT_TRUE(output_sz>0); + EXPECT_TRUE(NULL!=strstr(output, custom)); + free(output); +} + +int main(int argc, char ** argv) +{ ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } -- cgit v1.2.3