diff options
| author | fengweihao <[email protected]> | 2024-11-20 10:03:12 +0800 |
|---|---|---|
| committer | fengweihao <[email protected]> | 2024-11-20 10:03:12 +0800 |
| commit | ff436e3f26b93d3c6a71b650ca917643fc5e4d54 (patch) | |
| tree | bff1ef36de84407b3bc8cf66e0e423865b8c704a /plugin/business/tsg-http/test | |
| parent | bbf084acad01102befc1fdfe916bc7209da08c50 (diff) | |
TSG-23793 Fixed the issue where comments in the HTML page containing <head> or <body> tags would cause the inserted script to fail
Diffstat (limited to 'plugin/business/tsg-http/test')
| -rw-r--r-- | plugin/business/tsg-http/test/test_pattern_replace.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
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 <stdio.h> #include <gtest/gtest.h> - TEST(PatternReplace, Grouping1) { const char* find="(?<name1>John)|(?<name2>李梅梅)|(?<name3>Jake)"; @@ -305,9 +304,38 @@ TEST(PatternInsert, BeforeBody) free(output); } -int main(int argc, char ** argv) +TEST(PatternInsert, HtmlCommentsContain) +{ + char input[]="<!doctype html><!--<html><head><title></title><body></body></head></html>--><html><head><title></title><body></body></head></html>"; + 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[]="<!doctype html><!--<html><title></title></html>--><html><head></head><!--<html><body></body></html>--><title></title><body></body></html>"; + 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(); } |
