diff options
Diffstat (limited to 'test/rexml/test_core.rb')
-rw-r--r-- | test/rexml/test_core.rb | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/test/rexml/test_core.rb b/test/rexml/test_core.rb index 46036d7f12..41e6e43540 100644 --- a/test/rexml/test_core.rb +++ b/test/rexml/test_core.rb @@ -1,4 +1,4 @@ -# coding: binary +# -*- coding: utf-8 -*- # frozen_string_literal: false require_relative "rexml_test_utils" @@ -116,6 +116,54 @@ module REXMLTests name4='test4'/>).join(' '), e.to_s end + def test_attribute_namespace_conflict + # https://www.w3.org/TR/xml-names/#uniqAttrs + message = <<-MESSAGE +Duplicate attribute "a" +Line: 4 +Position: 140 +Last 80 unconsumed characters: + MESSAGE + assert_raise_with_message(REXML::ParseException, message) do + Document.new(<<-XML) +<!-- http://www.w3.org is bound to n1 and n2 --> +<x xmlns:n1="http://www.w3.org" + xmlns:n2="http://www.w3.org" > + <bad a="1" a="2" /> + <bad n1:a="1" n2:a="2" /> +</x> + XML + end + end + + def test_attribute_default_namespace + # https://www.w3.org/TR/xml-names/#uniqAttrs + document = Document.new(<<-XML) +<!-- http://www.w3.org is bound to n1 and is the default --> +<x xmlns:n1="http://www.w3.org" + xmlns="http://www.w3.org" > + <good a="1" b="2" /> + <good a="1" n1:a="2" /> +</x> + XML + attributes = document.root.elements.collect do |element| + element.attributes.each_attribute.collect do |attribute| + [attribute.prefix, attribute.namespace, attribute.name] + end + end + assert_equal([ + [ + ["", "", "a"], + ["", "", "b"], + ], + [ + ["", "", "a"], + ["n1", "http://www.w3.org", "a"], + ], + ], + attributes) + end + def test_cdata test = "The quick brown fox jumped & < & < \" ' |