diff options
author | Paul Phillips <paulp@improving.org> | 2010-01-11 17:16:56 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-01-11 17:16:56 +0000 |
commit | c6c3b44b0c4e019b9e65a88300c89f7e617ad56c (patch) | |
tree | 206a5fbb4e013fe0bc1c250d0f6888759605d0b0 | |
parent | 91e88b3f7d4a2765c11bf4ac5495eb7c329bc18e (diff) | |
download | scala-c6c3b44b0c4e019b9e65a88300c89f7e617ad56c.tar.gz scala-c6c3b44b0c4e019b9e65a88300c89f7e617ad56c.tar.bz2 scala-c6c3b44b0c4e019b9e65a88300c89f7e617ad56c.zip |
Fix and test case for #2364, which regressed wi...
Fix and test case for #2364, which regressed with the fix to #2721.
-rw-r--r-- | src/library/scala/xml/parsing/FactoryAdapter.scala | 4 | ||||
-rw-r--r-- | test/files/run/bug2364.check | 1 | ||||
-rw-r--r-- | test/files/run/bug2364.scala | 57 |
3 files changed, 61 insertions, 1 deletions
diff --git a/src/library/scala/xml/parsing/FactoryAdapter.scala b/src/library/scala/xml/parsing/FactoryAdapter.scala index 2385f645b5..a83f9677a1 100644 --- a/src/library/scala/xml/parsing/FactoryAdapter.scala +++ b/src/library/scala/xml/parsing/FactoryAdapter.scala @@ -135,7 +135,9 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node hStack push null var m: MetaData = Null - var scpe: NamespaceBinding = scopeStack.top + var scpe: NamespaceBinding = + if (scopeStack.isEmpty) TopScope + else scopeStack.top for (i <- 0 until attributes.getLength()) { val qname = attributes getQName i diff --git a/test/files/run/bug2364.check b/test/files/run/bug2364.check new file mode 100644 index 0000000000..219305e43a --- /dev/null +++ b/test/files/run/bug2364.check @@ -0,0 +1 @@ +<test></test> diff --git a/test/files/run/bug2364.scala b/test/files/run/bug2364.scala new file mode 100644 index 0000000000..0d1600c048 --- /dev/null +++ b/test/files/run/bug2364.scala @@ -0,0 +1,57 @@ +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import com.sun.xml.internal.fastinfoset._ +import com.sun.xml.internal.fastinfoset.sax._ +import scala.xml.parsing.NoBindingFactoryAdapter +import scala.xml._ + +object Test { + def main(args: Array[String]) { + val node = <test/> + val bytes = new ByteArrayOutputStream + val serializer = new SAXDocumentSerializer() + + serializer.setOutputStream(bytes) + serializer.startDocument() + serialize(node, serializer) + serializer.endDocument() + println(parse(new ByteArrayInputStream(bytes.toByteArray))) + } + def serialize(node: Node, serializer: SAXDocumentSerializer) { + node match { + case _ : ProcInstr | _ : Comment | _ : EntityRef => + case x : Atom[_] => + val chars = x.text.toCharArray + serializer.characters(chars, 0, chars.length) + case _ : Elem => + serializer.startElement("", node.label.toLowerCase, node.label.toLowerCase, attributes(node.attributes)) + for (m <- node.child) serialize(m, serializer) + serializer.endElement("", node.label.toLowerCase, node.label.toLowerCase) + } + } + def parse(str: ByteArrayInputStream) = { + val parser = new SAXDocumentParser + val fac = new NoBindingFactoryAdapter + + parser.setContentHandler(fac) + try { + parser.parse(str) + } catch { + case x: Exception => + x.printStackTrace + } + fac.rootElem + } + def attributes(d: MetaData) = { + val attrs = new AttributesHolder + + if (d != null) { + for (attr <- d) { + val sb = new StringBuilder() + Utility.sequenceToXML(attr.value, TopScope, sb, true) + attrs.addAttribute(new QualifiedName("", "", attr.key.toLowerCase), sb.toString) + } + } + attrs + } +} |