Skip to content

Commit 9033cad

Browse files
authored
Merge pull request #252 from ashawley/fix-fail-empty-string
Fix failure for empty string match
2 parents f3841aa + 389cdce commit 9033cad

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: shared/src/main/scala/scala/xml/NodeSeq.scala

+2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
140140
* The document order is preserved.
141141
*/
142142
def \\(that: String): NodeSeq = {
143+
def fail = throw new IllegalArgumentException(that)
143144
def filt(cond: (Node) => Boolean) = this flatMap (_.descendant_or_self) filter cond
144145
that match {
146+
case "" => fail
145147
case "_" => filt(!_.isAtom)
146148
case _ if that(0) == '@' => filt(!_.isAtom) flatMap (_ \ that)
147149
case _ => filt(x => !x.isAtom && x.label == that)

Diff for: shared/src/test/scala/scala/xml/XMLTest.scala

+10
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ class XMLTest {
145145
assertEquals(expected, actual)
146146
}
147147

148+
@UnitTest(expected=classOf[IllegalArgumentException])
149+
def failEmptyStringChildren: Unit = {
150+
<x/> \ ""
151+
}
152+
153+
@UnitTest(expected=classOf[IllegalArgumentException])
154+
def failEmptyStringDescendants: Unit = {
155+
<x/> \\ ""
156+
}
157+
148158
@UnitTest
149159
def namespaces: Unit = {
150160
val cuckoo = <cuckoo xmlns="http://cuckoo.com">

0 commit comments

Comments
 (0)