File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,7 @@ module Private
156
156
default_entities . each do |term |
157
157
DEFAULT_ENTITIES_PATTERNS [ term ] = /&#{ term } ;/
158
158
end
159
+ XML_PREFIXED_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
159
160
end
160
161
private_constant :Private
161
162
@@ -185,7 +186,7 @@ def stream=( source )
185
186
@tags = [ ]
186
187
@stack = [ ]
187
188
@entities = [ ]
188
- @namespaces = { }
189
+ @namespaces = { "xml" => Private :: XML_PREFIXED_NAMESPACE }
189
190
@namespaces_restore_stack = [ ]
190
191
end
191
192
@@ -790,7 +791,7 @@ def parse_attributes(prefixes)
790
791
@source . match ( /\s */um , true )
791
792
if prefix == "xmlns"
792
793
if local_part == "xml"
793
- if value != "http://www.w3.org/XML/1998/namespace"
794
+ if value != Private :: XML_PREFIXED_NAMESPACE
794
795
msg = "The 'xml' prefix must not be bound to any other namespace " +
795
796
"(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
796
797
raise REXML ::ParseException . new ( msg , @source , self )
Original file line number Diff line number Diff line change @@ -23,5 +23,40 @@ def test_large_xml
23
23
parser . position < xml . bytesize
24
24
end
25
25
end
26
+
27
+ def test_attribute_prefixed_by_xml
28
+ xml = <<-XML
29
+ <?xml version="1.0" encoding="UTF-8"?>
30
+ <!DOCTYPE html>
31
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
32
+ <head>
33
+ <title>XHTML Document</title>
34
+ </head>
35
+ <body>
36
+ <h1>XHTML Document</h1>
37
+ <p xml:lang="ja" lang="ja">この段落は日本語です。</p>
38
+ </body>
39
+ </html>
40
+ XML
41
+
42
+ parser = REXML ::Parsers ::BaseParser . new ( xml )
43
+ 5 . times { parser . pull }
44
+
45
+ html = parser . pull
46
+ assert_equal ( [ :start_element ,
47
+ "html" ,
48
+ { "xmlns" => "http://www.w3.org/1999/xhtml" ,
49
+ "xml:lang" => "en" ,
50
+ "lang" => "en" } ] ,
51
+ html )
52
+
53
+ 15 . times { parser . pull }
54
+
55
+ p = parser . pull
56
+ assert_equal ( [ :start_element ,
57
+ "p" ,
58
+ { "xml:lang" => "ja" , "lang" => "ja" } ] ,
59
+ p )
60
+ end
26
61
end
27
62
end
You can’t perform that action at this time.
0 commit comments