diff options
author | Burak Emir <emir@epfl.ch> | 2008-03-27 05:07:03 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2008-03-27 05:07:03 +0000 |
commit | 54f611edb31c867a46a2df4d83df7068358ea39e (patch) | |
tree | bfd01e22635ae62923ae3f0095f090491e484ded | |
parent | ef488e9e397a045afe5ad6d2c2a4c6b4e8b1cdfa (diff) | |
download | scala-54f611edb31c867a46a2df4d83df7068358ea39e.tar.gz scala-54f611edb31c867a46a2df4d83df7068358ea39e.tar.bz2 scala-54f611edb31c867a46a2df4d83df7068358ea39e.zip |
reverted parseattrubtevalue hack, fixed attribu...
reverted parseattrubtevalue hack, fixed attribute value parsing
-rw-r--r-- | src/library/scala/xml/PrefixedAttribute.scala | 2 | ||||
-rw-r--r-- | src/library/scala/xml/UnprefixedAttribute.scala | 4 | ||||
-rw-r--r-- | src/library/scala/xml/parsing/FactoryAdapter.scala | 4 | ||||
-rw-r--r-- | src/library/scala/xml/parsing/MarkupParser.scala | 17 | ||||
-rw-r--r-- | test/files/jvm/t0632.check | 12 | ||||
-rw-r--r-- | test/files/jvm/t0632.scala | 22 |
6 files changed, 48 insertions, 13 deletions
diff --git a/src/library/scala/xml/PrefixedAttribute.scala b/src/library/scala/xml/PrefixedAttribute.scala index 0ee62b9cd7..78b28b17b1 100644 --- a/src/library/scala/xml/PrefixedAttribute.scala +++ b/src/library/scala/xml/PrefixedAttribute.scala @@ -28,7 +28,7 @@ class PrefixedAttribute(val pre: String, /** same as this(key, Utility.parseAttributeValue(value), next) */ def this(pre: String, key: String, value: String, next: MetaData) = - this(pre, key, Utility.parseAttributeValue(value), next) + this(pre, key, Text(value), next) /* // the problem here is the fact that we cannot remove the proper attribute from diff --git a/src/library/scala/xml/UnprefixedAttribute.scala b/src/library/scala/xml/UnprefixedAttribute.scala index adaca90d97..e9f5dff0c5 100644 --- a/src/library/scala/xml/UnprefixedAttribute.scala +++ b/src/library/scala/xml/UnprefixedAttribute.scala @@ -19,9 +19,9 @@ class UnprefixedAttribute(val key: String, val value: Seq[Node], next1: MetaData val next = if (value ne null) next1 else next1.remove(key) - /** same as this(key, Utility.parseAttributeValue(value), next) */ + /** same as this(key, Text(value), next) */ def this(key: String, value: String, next: MetaData) = - this(key, if (value ne null) Utility.parseAttributeValue(value) else {val z:NodeSeq=null;z}, next) + this(key, if (value ne null) Text(value) else {val z:NodeSeq=null;z}, next) /** same as this(key, value.get, next), or no attribute if value is None */ def this(key: String, value: Option[Seq[Node]], next: MetaData) = diff --git a/src/library/scala/xml/parsing/FactoryAdapter.scala b/src/library/scala/xml/parsing/FactoryAdapter.scala index 2ca0527a6b..4b8ca9f9cc 100644 --- a/src/library/scala/xml/parsing/FactoryAdapter.scala +++ b/src/library/scala/xml/parsing/FactoryAdapter.scala @@ -145,14 +145,14 @@ abstract class FactoryAdapter extends DefaultHandler() { case _ => new NamespaceBinding(key, value, scpe) } else - m = new PrefixedAttribute(pre, key, value, m) + m = new PrefixedAttribute(pre, key, Text(value), m) } else if ("xmlns" /*XML.xmlns*/ == qname) scpe = value.length() match { case 0 => new NamespaceBinding(null, null, scpe) case _ => new NamespaceBinding(null, value, scpe) } else - m = new UnprefixedAttribute(qname, value, m) + m = new UnprefixedAttribute(qname, Text(value), m) } scopeStack.push(scpe) attribStack.push(m) diff --git a/src/library/scala/xml/parsing/MarkupParser.scala b/src/library/scala/xml/parsing/MarkupParser.scala index b8f15162c7..541cc65ac2 100644 --- a/src/library/scala/xml/parsing/MarkupParser.scala +++ b/src/library/scala/xml/parsing/MarkupParser.scala @@ -294,13 +294,13 @@ trait MarkupParser extends AnyRef with TokenTests { self: MarkupParser with Mar case Some(prefix) => val key = qname.substring(prefix.length+1, qname.length); - aMap = new PrefixedAttribute(prefix, key, value, aMap); + aMap = new PrefixedAttribute(prefix, key, Text(value), aMap); case _ => if( qname == "xmlns" ) scope = new NamespaceBinding(null, value, scope); else - aMap = new UnprefixedAttribute(qname, value, aMap); + aMap = new UnprefixedAttribute(qname, Text(value), aMap); } if ((ch != '/') && (ch != '>') && ('?' != ch)) @@ -1174,7 +1174,7 @@ trait MarkupParser extends AnyRef with TokenTests { self: MarkupParser with Mar def normalizeAttributeValue(attval: String): String = { val s: Seq[Char] = attval val it = s.elements - while(it.hasNext) { + while (it.hasNext) { it.next match { case ' '|'\t'|'\n'|'\r' => cbuf.append(' '); @@ -1191,12 +1191,13 @@ trait MarkupParser extends AnyRef with TokenTests { self: MarkupParser with Mar d = it.next } while(d != ';'); nbuf.toString() match { - //case "lt" => cbuf.append('<') - //case "gt" => cbuf.append('>') - //case "amp" => cbuf.append('&') - //case "quote" => cbuf.append('"') + case "lt" => cbuf.append('<') + case "gt" => cbuf.append('>') + case "amp" => cbuf.append('&') + case "apos" => cbuf.append('\'') + case "quot" => cbuf.append('"') + case "quote" => cbuf.append('"') case name => - //don't handle entityrefs for now cbuf.append('&') cbuf.append(name) cbuf.append(';') diff --git a/test/files/jvm/t0632.check b/test/files/jvm/t0632.check new file mode 100644 index 0000000000..3185410a75 --- /dev/null +++ b/test/files/jvm/t0632.check @@ -0,0 +1,12 @@ +<foo x="&"></foo> +<foo x="&"></foo> +<foo x="&"></foo> +<foo x="&"></foo> +<foo x="&amp;"></foo> +<foo x="&amp;"></foo> +<foo x="&amp;"></foo> +<foo x="&amp;"></foo> +<foo x="&&"></foo> +<foo x="&&"></foo> +<foo x="&&"></foo> +<foo x="&&"></foo> diff --git a/test/files/jvm/t0632.scala b/test/files/jvm/t0632.scala new file mode 100644 index 0000000000..a2bb5aa7f4 --- /dev/null +++ b/test/files/jvm/t0632.scala @@ -0,0 +1,22 @@ +object Test { +import scala.io.Source.fromString +import scala.xml.parsing.ConstructingParser.fromSource +import scala.xml.TopScope + def parse(s:String) = fromSource(fromString(s), false).element(TopScope) + def main(argv : Array[String]) : Unit = { + + println(parse("<foo x='&'/>")) + println(xml.XML.loadString("<foo x='&'/>")) + println(<foo x="&"/>) + println(<foo x={ "&" }/>) + + println(xml.XML.loadString("<foo x='&amp;'/>")) + println(parse("<foo x='&amp;'/>")) + println(<foo x="&amp;"/>) + println(<foo x={ "&" }/>) + println(xml.XML.loadString("<foo x='&&'/>")) + println(parse("<foo x='&&'/>")) + println(<foo x="&&"/>) + println(<foo x={ "&&" }/>) + } +} |