Skip to content

OffsetPosition.lineContents fails when the last character is a newline #128

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

Closed
justinp opened this issue Oct 10, 2017 · 1 comment
Closed

Comments

@justinp
Copy link
Contributor

justinp commented Oct 10, 2017

Like the description says... it throws a java.lang.StringIndexOutOfBoundsException: String index out of range: -1 because it assumes that the last character is not a newline. Here's a small test program demonstrating the bug:

object Bug extends scala.util.parsing.combinator.RegexParsers {
  override def skipWhitespace = false

  val whitespace: Parser[String] = "\\s+".r
  val anything = elem('a')

  val line = log(whitespace <~ anything)("line")

  def main(args: Array[String]): Unit = {
    println(parse(line, "\n"))
  }
}
justinp added a commit to justinp/scala-parser-combinators that referenced this issue Oct 10, 2017
SethTisue added a commit that referenced this issue Jun 9, 2018
#128: prevent OutOfBoundsException on trailing newline
@SethTisue
Copy link
Member

fixed by #129

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

No branches or pull requests

2 participants