diff options
author | Ville Skytt? <ville.skytta@iki.fi> | 2011-12-12 21:30:42 +0200 |
---|---|---|
committer | Ville Skytt? <ville.skytta@iki.fi> | 2011-12-12 21:30:42 +0200 |
commit | 0f1cba48f4eafe701910116f917a2c882534e992 (patch) | |
tree | 0b9c6feb2167934672448aae85b04afaf040b607 | |
parent | b075f22c75cf7386e6ce59e78ccb7a1cd7186a96 (diff) | |
download | markup-validator-0f1cba48f4eafe701910116f917a2c882534e992.zip markup-validator-0f1cba48f4eafe701910116f917a2c882534e992.tar.gz markup-validator-0f1cba48f4eafe701910116f917a2c882534e992.tar.bz2 |
Don't change line numbers when overriding multiline charset indication.
-rwxr-xr-x | httpd/cgi-bin/check | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/httpd/cgi-bin/check b/httpd/cgi-bin/check index 56da108..11991f3 100755 --- a/httpd/cgi-bin/check +++ b/httpd/cgi-bin/check @@ -2301,13 +2301,22 @@ sub override_charset ($$) my $content = join("\n", @{$File->{Content}}); + # Flatten newlines (so that we don't end up changing line numbers while + # overriding) and comment-escape a string. + sub escape_original ($) + { + my $str = shift; + $str =~ tr/\r\n/ /; + return &escape_comment($str); + } + # <?xml encoding="charset"?> $content =~ s/( (^<\?xml\b[^>]*?${ws}encoding${ws}*=${ws}*(["'])) (${cs}) (\3.*?\?>) )/lc($4) eq lc($charset) ? - "$1" : "$2$charset$5<!-- " . &escape_comment($1) ." -->"/esx; + "$1" : "$2$charset$5<!-- " . &escape_original($1) . " -->"/esx; # <meta charset="charset"> $content =~ s/( @@ -2315,7 +2324,7 @@ sub override_charset ($$) (${cs}) (.*?>) )/lc($3) eq lc($charset) ? - "$1" : "$2$charset$4<!-- " . &escape_comment($1) . " -->"/esix; + "$1" : "$2$charset$4<!-- " . &escape_original($1) . " -->"/esix; # <meta http-equiv="content-type" content="some/type; charset=charset"> $content =~ s/( @@ -2325,7 +2334,7 @@ sub override_charset ($$) (${cs}) (.*?>) )/lc($3) eq lc($charset) ? - "$1" : "$2$charset$4<!-- " . &escape_comment($1) . " -->"/esix; + "$1" : "$2$charset$4<!-- " . &escape_original($1) . " -->"/esix; # <meta content="some/type; charset=charset" http-equiv="content-type"> $content =~ s/( @@ -2334,7 +2343,7 @@ sub override_charset ($$) (${cs}) ([^>]*?${ws}http-equiv${ws}*=${ws}*["']?${ws}*content-type\b.*?>) )/lc($3) eq lc($charset) ? - "$1" : "$2$charset$4<!-- " . &escape_comment($1) . " -->"/esix; + "$1" : "$2$charset$4<!-- " . &escape_original($1) . " -->"/esix; $File->{Content} = [split /\n/, $content]; } |