TSG-23793 Fixed the issue where comments in the HTML page containing <head> or <body> tags would cause the inserted script to fail
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user