summaryrefslogtreecommitdiff
path: root/test/files/run/t6939.scala
diff options
context:
space:
mode:
authorEugene Yokota <eed3si9n@gmail.com>2013-01-25 11:44:09 -0500
committerEugene Yokota <eed3si9n@gmail.com>2013-01-27 03:38:05 -0500
commitb6f898f0811a72b423b6bef17cd2bf6791f1f5f0 (patch)
treea91ca3bc5f09edb1e6a72b95a98446e20c4beccc /test/files/run/t6939.scala
parent22dcec63745c2906c3c0ad636049e4ab0f73233c (diff)
downloadscala-b6f898f0811a72b423b6bef17cd2bf6791f1f5f0.tar.gz
scala-b6f898f0811a72b423b6bef17cd2bf6791f1f5f0.tar.bz2
scala-b6f898f0811a72b423b6bef17cd2bf6791f1f5f0.zip
SI-6939 Fix namespace binding (xmlns) not overriding outer binding
Given a nested XML literal to the compiler Elem instance is generated with namespace binding of the inner element copying that of the outer element: val foo = <x:foo xmlns:x="http://foo.com/"> <x:bar xmlns:x="http://bar.com/"><x:baz/></x:bar></x:foo> With the above example, `foo.child.head.scope.toString` returns " xmlns:x="http://bar.com/" xmlns:x="http://foo.com/"" This is incorrect since the outer xmls:x should be overridden by the inner binding. XML library also parses XML document in a similar manner: val foo2 = scala.xml.XML.loadString("""<x:foo xmlns:x="http://foo.com/"><x:bar xmlns:x="http://bar.com/"><x:baz/></x:bar></x:foo>""") Despite this erroneous behavior, since the structure of NamespaceBinding class is designed to be singly-linked list, the stacking of namespace bindings allows constant-time creation with simple implementation. Since the inner namespace binding comes before the outer one, query methods like `getURI` method behave correctly. Because this bug is manifested when Elem is turned back into XML string, it could be fixed by shadowing the redefined namespace binding right when buildString is called. With this change `foo.child.head.scope.toString` now returns: " xmlns:x="http://bar.com/""
Diffstat (limited to 'test/files/run/t6939.scala')
-rw-r--r--test/files/run/t6939.scala13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/files/run/t6939.scala b/test/files/run/t6939.scala
new file mode 100644
index 0000000000..9fe721555f
--- /dev/null
+++ b/test/files/run/t6939.scala
@@ -0,0 +1,13 @@
+object Test extends App {
+ val foo = <x:foo xmlns:x="http://foo.com/"><x:bar xmlns:x="http://bar.com/"><x:baz/></x:bar></x:foo>
+ assert(foo.child.head.scope.toString == """ xmlns:x="http://bar.com/"""")
+
+ val fooDefault = <foo xmlns="http://foo.com/"><bar xmlns="http://bar.com/"><baz/></bar></foo>
+ assert(fooDefault.child.head.scope.toString == """ xmlns="http://bar.com/"""")
+
+ val foo2 = scala.xml.XML.loadString("""<x:foo xmlns:x="http://foo.com/"><x:bar xmlns:x="http://bar.com/"><x:baz/></x:bar></x:foo>""")
+ assert(foo2.child.head.scope.toString == """ xmlns:x="http://bar.com/"""")
+
+ val foo2Default = scala.xml.XML.loadString("""<foo xmlns="http://foo.com/"><bar xmlns="http://bar.com/"><baz/></bar></foo>""")
+ assert(foo2Default.child.head.scope.toString == """ xmlns="http://bar.com/"""")
+}