Skip to content

Commit

Permalink
Merge pull request alibaba#281 from taoyuanyuan/t
Browse files Browse the repository at this point in the history
Bugfix: fixed a bug of trim module.
  • Loading branch information
yaoweibin committed Jul 31, 2013
2 parents ff9004d + 5db1b4d commit 94158c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/http/modules/ngx_http_trim_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ ngx_http_trim_parse(ngx_http_request_t *r, ngx_buf_t *buf,
}

ctx->state = trim_state_text_whitespace;
if (ctx->prev == ch || ctx->prev == ' ' || ctx->prev == '>') {
if (ctx->prev == ch || ctx->prev == ' ') {
continue;

} else {
Expand Down
32 changes: 16 additions & 16 deletions tests/test-nginx/cases/trim.t
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ __DATA__
<textarea>
hello
world!
</textarea><pre>
</textarea> <pre>
hello world!
</pre><!--[if IE]> hello world ! <![endif]--><!--[if !IE ]>--> hello world ! <!--<![endif]-->'
</pre> <!--[if IE]> hello world ! <![endif]--> <!--[if !IE ]>--> hello world ! <!--<![endif]--> '

=== TEST 2: trim within other tags
--- config
Expand All @@ -63,7 +63,7 @@ is good to see you </body>
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<body>hello world, it is good to see you </body><body>hello world, it is good to see you </body>'
<body>hello world, it is good to see you </body> <body>hello world, it is good to see you </body> '

=== TEST 3: trim within non-ie comment
--- config
Expand All @@ -83,7 +83,7 @@ is good to see you </body>
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<body>hello </body><!--[if IE]> hello world ! <![endif]--><!--[if !IE ]>--> hello world ! <!--<![endif]-->'
<body>hello </body> <!--[if IE]> hello world ! <![endif]--> <!--[if !IE ]>--> hello world ! <!--<![endif]--> '

=== TEST 4: do not trim within tag quote
--- config
Expand All @@ -101,7 +101,7 @@ style="text-align: center;">hello world, it
--- response_body eval
'<!DOCTYPE html>
<body
style="text-align: center;">hello world, it is good to see you </body>'
style="text-align: center;">hello world, it is good to see you </body> '

=== TEST 5: trim newline
--- config
Expand Down Expand Up @@ -131,7 +131,7 @@ style="text-align: center;">hello world, it is good to see you </body>'
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<html><body>hello world!<body> <html>'
<html> <body>hello world!<body> <html> '

=== TEST 6: return zero size
--- config
Expand Down Expand Up @@ -171,7 +171,7 @@ style="text-align: center;">hello world, it is good to see you </body>'
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
< <PRE>hello world ! </pre><2 <pre>hello world ! </pre><<< <pre>hello world ! </pre>< < <pre>hello world ! </pre>< <<pre>hello world ! </pre><x <<pre>hello world ! </pre>< <<<!doctype html>'
< <PRE>hello world ! </pre> <2 <pre>hello world ! </pre> <<< <pre>hello world ! </pre> < < <pre>hello world ! </pre> < <<pre>hello world ! </pre> <x <<pre>hello world ! </pre> < <<<!doctype html> '

=== TEST 8: trim Chinese characters
--- config
Expand Down Expand Up @@ -204,7 +204,7 @@ style="text-align: center;">hello world, it is good to see you </body>'
GET /trim.html
--- response_body eval
'<!DOCTYPE html>
<body>hello world, it is good to see you </body>'
<body>hello world, it is good to see you </body> '

=== TEST 10: if $arg_http_trim is off, trim off.
--- config
Expand Down Expand Up @@ -251,9 +251,9 @@ document.write("hello world");
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<script>document.write("hello world");</script><script type="text/javascript"></script><script type="text/vbscript">
<script>document.write("hello world");</script> <script type="text/javascript"></script> <script type="text/vbscript">
/* no javscript code !*/
</script>'
</script> '

=== TEST 12: do not tirm javascript quote and RE
--- config
Expand All @@ -277,7 +277,7 @@ str.replace( / /,"hello");
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<script>document.write("hello world");document.write("hello \" world");var reg=/hello \/ world /g;var reg=/hello \/ world /g;str.replace(/ /,"hello");str.replace(/ /,"hello");</script>'
<script>document.write("hello world");document.write("hello \" world");var reg=/hello \/ world /g;var reg=/hello \/ world /g;str.replace(/ /,"hello");str.replace(/ /,"hello");</script> '

=== TEST 13: trim css comment
--- config
Expand All @@ -299,7 +299,7 @@ body {
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<style type="text/css">body {background-color:black;}</style>'
<style type="text/css">body {background-color:black;}</style> '

=== TEST 14: do not trim css quote
--- config
Expand All @@ -319,7 +319,7 @@ body {
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<style type="text/css">"hello world");"hello \" world");"hello \\\\\" world");</style>'
<style type="text/css">"hello world");"hello \" world");"hello \\\\\" world");</style> '

=== TEST 15 trim aplus.js
--- config
Expand All @@ -343,7 +343,7 @@ d.getElementsByTagName("head")[0].appendChild(t);
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<script type="text/javascript">(function (d) {var t=d.createElement("script");t.type="text/javascript";t.async=true;t.id="tb-beacon-aplus";t.setAttribute("exparams","category=&userid=&aplus");t.src=("https:"==d.location.protocol?"https://s":"http://a")+".tbcdn.cn/s/aplus_v2.js";d.getElementsByTagName("head")[0].appendChild(t);})(document);</script>'
<script type="text/javascript">(function (d) {var t=d.createElement("script");t.type="text/javascript";t.async=true;t.id="tb-beacon-aplus";t.setAttribute("exparams","category=&userid=&aplus");t.src=("https:"==d.location.protocol?"https://s":"http://a")+".tbcdn.cn/s/aplus_v2.js";d.getElementsByTagName("head")[0].appendChild(t);})(document);</script> '

=== TEST 15: do not trim css comment of child selector hack
--- config
Expand All @@ -363,7 +363,7 @@ html >/**/ body p {
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<style type="text/css">html >/**/ body p {color:blue;}</style>'
<style type="text/css">html >/**/ body p {color:blue;}</style> '

=== TEST 16: do not trim css comment of IE5/Mac hack
--- config
Expand All @@ -390,4 +390,4 @@ html >/**/ body p {
color: khaki;
}
/**/
</style>'
</style> '

0 comments on commit 94158c1

Please sign in to comment.