Skip to content

Commit 39bfba1

Browse files
paulpadriaanm
authored andcommitted
Revert "Accept prefixed xml attributes with null value"
This reverts commit 51089b34a7a535498dee42e6465d4d577d65b7d5. A scaladoc test is failing and I have no time to look at it.
1 parent 2ffd24b commit 39bfba1

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

src/library/scala/xml/PrefixedAttribute.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@ package scala.xml
1313
*
1414
* @param pre ...
1515
* @param key ...
16-
* @param value the attribute value
16+
* @param value the attribute value, which may not be null
1717
* @param next ...
1818
*/
1919
class PrefixedAttribute(
2020
val pre: String,
2121
val key: String,
2222
val value: Seq[Node],
23-
val next1: MetaData)
23+
val next: MetaData)
2424
extends Attribute
2525
{
26-
val next = if (value ne null) next1 else next1.remove(key)
26+
if (value eq null)
27+
throw new UnsupportedOperationException("value is null")
2728

28-
/** same as this(pre, key, Text(value), next), or no attribute if value is null */
29+
/** same as this(key, Utility.parseAttributeValue(value), next) */
2930
def this(pre: String, key: String, value: String, next: MetaData) =
30-
this(pre, key, if (value ne null) Text(value) else null: NodeSeq, next)
31-
32-
/** same as this(pre, key, value.get, next), or no attribute if value is None */
33-
def this(pre: String, key: String, value: Option[Seq[Node]], next: MetaData) =
34-
this(pre, key, value.orNull, next)
31+
this(pre, key, Text(value), next)
3532

3633
/** Returns a copy of this unprefixed attribute with the given
3734
* next field.

test/files/run/xml-attribute.scala

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,10 @@ object Test {
55
val noAttr = <t/>
66
val attrNull = <t a={ null: String }/>
77
val attrNone = <t a={ None: Option[Seq[Node]] }/>
8-
val preAttrNull = <t p:a={ null: String }/>
9-
val preAttrNone = <t p:a={ None: Option[Seq[Node]] }/>
108
assert(noAttr == attrNull)
119
assert(noAttr == attrNone)
12-
assert(noAttr == preAttrNull)
13-
assert(noAttr == preAttrNone)
14-
15-
val noAttrStr = "<t></t>"
16-
assert(noAttr.toString() == noAttrStr)
17-
assert(attrNull.toString() == noAttrStr)
18-
assert(attrNone.toString() == noAttrStr)
19-
assert(preAttrNull.toString() == noAttrStr)
20-
assert(preAttrNone.toString() == noAttrStr)
21-
22-
val xml1 = <t b="1" d="2"/>
23-
val xml2 = <t a={ null: String } p:a={ null: String } b="1" c={ null: String } d="2"/>
24-
val xml3 = <t b="1" c={ null: String } d="2" a={ null: String } p:a={ null: String }/>
25-
assert(xml1 == xml2)
26-
assert(xml1 == xml3)
27-
28-
val xml1Str = "<t d=\"2\" b=\"1\"></t>"
29-
assert(xml1.toString() == xml1Str)
30-
assert(xml2.toString() == xml1Str)
31-
assert(xml3.toString() == xml1Str)
10+
assert(noAttr.toString() == "<t></t>")
11+
assert(attrNull.toString() == "<t></t>")
12+
assert(attrNone.toString() == "<t></t>")
3213
}
3314
}

0 commit comments

Comments
 (0)