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

SIP-11 (String interpolation): escape characters in processed strings are (somehow) interpreted #5614

Closed
scabug opened this issue Mar 26, 2012 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Mar 26, 2012

The interpretation of StringContext.s is strange when applied to the string literal s"a\nb". According to SIP-11 (String Interpolation) the standard interpolation should replace every escape character sequence by the denoted character, therefore I expected a result of length 3.

scala> s"a\nb"
res0: String =
a\nb
b

scala> res0.length
res1: Int = 6
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 26, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5614?orig=1
Reporter: @dgruntz
Affected Versions: 2.10.0-M2

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 26, 2012

@dgruntz said:
Fix:

Change (in method treatEscapes, line 146 of File StringContext.scala)

    def output(ch: Char) = {
      bldr append str substring (start, cur)
      bldr append ch
      start = idx
    }

to

    def output(ch: Char) = {
      bldr append str.substring (start, cur)
      bldr append ch
      start = idx
    }

Explanation: in the current version, str is appended to the buffer, and then on the buffer substring is called (which has no effect), i.e. without sugar:
bldr.append(str).subsring(start, cur)

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 27, 2012

@cvogt said:
Can you please create a pull request including a test? Ask me if you have questions. Thx

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Apr 6, 2012

@dgruntz said:
fixed with scala/scala@017f48e

@scabug scabug closed this Apr 6, 2012
@scabug scabug added this to the 2.10.0-M2 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.