Skip to content

Commit 4852e43

Browse files
committed
Update handling of server side includes
ensure quotes are handled correctly when server side includes are added to attributes
1 parent 0723293 commit 4852e43

4 files changed

+79
-19
lines changed

Manifest.txt

+1
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,4 @@ lib/xml-apis.jar
235235
lib/xsd/xmlparser/nokogiri.rb
236236
patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch
237237
patches/libxml2/0002-Remove-script-macro-support.patch
238+
patches/libxml2/0003-Update-entities-to-remove-handling-of-ssi.patch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
From ffc08467744bd2305d41ca882c37fa30adf3a067 Mon Sep 17 00:00:00 2001
2+
From: Kevin Solorio <[email protected]>
3+
Date: Wed, 27 Feb 2019 14:34:17 -0800
4+
Subject: [PATCH 2/2] update entities.c to remove handling of ssi
5+
6+
---
7+
entities.c | 21 ---------------------
8+
1 file changed, 21 deletions(-)
9+
10+
diff --git a/entities.c b/entities.c
11+
index 43549bc5..5c4a2a60 100644
12+
--- a/entities.c
13+
+++ b/entities.c
14+
@@ -592,27 +592,6 @@ xmlEncodeEntitiesInternal(xmlDocPtr doc, const xmlChar *input, int attr) {
15+
* By default one have to encode at least '<', '>', '"' and '&' !
16+
*/
17+
if (*cur == '<') {
18+
- const xmlChar *end;
19+
-
20+
- /*
21+
- * Special handling of server side include in HTML attributes
22+
- */
23+
- if (html && attr &&
24+
- (cur[1] == '!') && (cur[2] == '-') && (cur[3] == '-') &&
25+
- ((end = xmlStrstr(cur, BAD_CAST "-->")) != NULL)) {
26+
- while (cur != end) {
27+
- *out++ = *cur++;
28+
- indx = out - buffer;
29+
- if (indx + 100 > buffer_size) {
30+
- growBufferReentrant();
31+
- out = &buffer[indx];
32+
- }
33+
- }
34+
- *out++ = *cur++;
35+
- *out++ = *cur++;
36+
- *out++ = *cur++;
37+
- continue;
38+
- }
39+
*out++ = '&';
40+
*out++ = 'l';
41+
*out++ = 't';
42+
--
43+
2.16.2
44+

test/html/test_attributes_do_not_support_macros.rb

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require "helper"
2+
3+
module Nokogiri
4+
module HTML
5+
class TestAttributesDoNotSupportMacros < Nokogiri::TestCase
6+
unless Nokogiri::VersionInfo.instance.libxml2? && Nokogiri::VersionInfo.instance.libxml2_using_system?
7+
8+
def test_attribute_macros_are_escaped
9+
html = "<p><i for=\"&{<test>}\"></i></p>"
10+
document = Nokogiri::HTML::Document.new
11+
nodes = document.parse(html)
12+
13+
assert_equal("<p><i for=\"&amp;{&lt;test&gt;}\"></i></p>", nodes[0].to_s)
14+
end
15+
16+
def test_libxml_escapes_server_side_includes
17+
original_html = %(<p><a href='<!--"><test>-->'></a></p>)
18+
document = Nokogiri::HTML::Document.new
19+
html = document.parse(original_html).to_s
20+
21+
assert_match(/!--%22&gt;&lt;test&gt;/, html)
22+
end
23+
24+
def test_libxml_escapes_server_side_includes_without_nested_quotes
25+
original_html = %(<p><i for="<!--<test>-->"></i></p>)
26+
document = Nokogiri::HTML::Document.new
27+
html = document.parse(original_html).to_s
28+
29+
assert_match(/&lt;!--&lt;test&gt;/, html)
30+
end
31+
end
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)