Skip to content

Fix failure for empty string match #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2018

Conversation

ashawley
Copy link
Member

Fixes #251.

@ashawley ashawley added this to the 1.1.1 milestone Aug 16, 2018
@ashawley
Copy link
Member Author

This is a low-risk change, since there is no behavior change. An exception is still thrown, it's just a different kind, IllegalArgmentException instead of StringIndexOutOfBoundsException.

Trying to match the empty string on descendants (or self) throws an
unexpected error:

    scala> <x/> \\ ""
    java.lang.StringIndexOutOfBoundsException: String index out of range: 0
      at java.lang.String.charAt(String.java:646)
      at scala.collection.immutable.StringOps$.apply$extension(StringOps.scala:37)
      at scala.xml.NodeSeq.$bslash$bslash(NodeSeq.scala:147)
      ...

The error should be consistent with what is thrown when trying to
match the empty string on just children:

    scala> <x/> \ ""
    java.lang.IllegalArgumentException
      at scala.xml.NodeSeq.fail$1(NodeSeq.scala:97)
      at scala.xml.NodeSeq.$bslash(NodeSeq.scala:120)
      ...

This was identified while writing ScalaCheck property tests.
@ashawley ashawley force-pushed the fix-fail-empty-string branch from a7cfed0 to 389cdce Compare August 28, 2018 13:08
@ashawley ashawley merged commit 9033cad into scala:master Aug 28, 2018
@ashawley ashawley deleted the fix-fail-empty-string branch August 28, 2018 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant