Skip to content
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

string.split('\n') not working #872

Closed
johanatan opened this issue Jul 24, 2014 · 9 comments
Closed

string.split('\n') not working #872

johanatan opened this issue Jul 24, 2014 · 9 comments
Assignees
Labels
bug Confirmed bug. Needs to be fixed.
Milestone

Comments

@johanatan
Copy link

Scala REPL:

Jonathans-MacBook-Pro:~ jonathan$ scala
Welcome to Scala version 2.11.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val string = "blah\nblah\nblah\nblah"
string: String =
blah
blah
blah
blah

scala> assert(string.split('\n').length == 4)

scala> assert(string.split('\n').length == 3)
java.lang.AssertionError: assertion failed
  at scala.Predef$.assert(Predef.scala:151)
  ... 32 elided

Scala JS:

def main(): Unit = {
  val string = "blah\nblah\nblah\nblah"
  assert(string.split('\n').length == 4)
}

=>
Uncaught java.lang.AssertionError: assertion failed

@sjrd
Copy link
Member

sjrd commented Jul 24, 2014

Quick note: a workaround is to use .split("\n") instead (with the string "\n" rather than the character '\n').

@sjrd
Copy link
Member

sjrd commented Jul 24, 2014

That would be an instance of the limitations on Regular Expressions documented here:
http://www.scala-js.org/doc/semantics.html
The implementation of StringLike.split(Char) uses the same escape sequences \Q and \E as StringLike.split(Array[Char]), which JavaScript regexps do not support.

@sjrd sjrd added the bug label Jul 24, 2014
@johanatan
Copy link
Author

It's an implementation detail of StringLike.split(Char) that regular expressions are involved. One wouldn't know that (or expect it) from its type signature.

@lihaoyi
Copy link
Contributor

lihaoyi commented Jul 24, 2014

Well it's the way it works in Java too, and it's what it says in the docs,
and tutorials, so...

On Thu, Jul 24, 2014 at 3:24 PM, Jonathan Leonard notifications@github.com
wrote:

It's an implementation detail of StringLike.split(Char) that regular
expressions are involved. One wouldn't know that (or expect it) from its
type signature.


Reply to this email directly or view it on GitHub
#872 (comment).

@lihaoyi
Copy link
Contributor

lihaoyi commented Jul 24, 2014

Unless I'm missing something (maybe I'm confused, but I've bumped into
something like this in Java before too, and got equally confused, so maybe
I'm confused now too)

EDIT: It looks like I was confused, please ignore me, sorry

On Thu, Jul 24, 2014 at 3:27 PM, Haoyi Li haoyi.sg@gmail.com wrote:

Well it's the way it works in Java too, and it's what it says in the docs,
and tutorials, so...

On Thu, Jul 24, 2014 at 3:24 PM, Jonathan Leonard <
notifications@github.com> wrote:

It's an implementation detail of StringLike.split(Char) that regular
expressions are involved. One wouldn't know that (or expect it) from its
type signature.


Reply to this email directly or view it on GitHub
#872 (comment).

@sjrd
Copy link
Member

sjrd commented Jul 24, 2014

I know. My second comment was more intended for us (the developers) as a reminder of the root cause of the issue, or that we have to document it. I'm sorry if that was not clear.

@johanatan
Copy link
Author

@sjrd Oh, no problem. Just wanted to make sure we're on the same page. After reading issue #105 it is clear now. Thanks! [Also, it seems from that discussion that this particular manifestation of the bug is a regression as StringLike.split(Char) was once hailed as an example where it worked as advertised]. :)

@sjrd
Copy link
Member

sjrd commented Jul 24, 2014

Ah ah! Good point! It seems e554140 was not sufficient as a fix for #65: it does not account for \n and other control characters.
We'll fix that in the next release.

@sjrd sjrd added this to the v0.5.3 milestone Jul 24, 2014
@gzm0 gzm0 self-assigned this Jul 26, 2014
@sjrd
Copy link
Member

sjrd commented Jul 26, 2014

Fixed in b6a3075

@sjrd sjrd closed this as completed Jul 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug. Needs to be fixed.
Projects
None yet
Development

No branches or pull requests

4 participants