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

Problem with string interpolation and null-byte #7094

Closed
scabug opened this issue Feb 7, 2013 · 3 comments
Closed

Problem with string interpolation and null-byte #7094

scabug opened this issue Feb 7, 2013 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Feb 7, 2013

Hi,
I found a problem with string interpolation functionality. Scala throws an exception if string ends with "\0" or if appending an expression value to the string ending with "\0".
Here are some examples which fail in scala console:

s"foo\0${java.util.UUID.randomUUID().toString}"
s"foo\0" + java.util.UUID.randomUUID().toString
(s"foo\0") + java.util.UUID.randomUUID().toString
val uid = java.util.UUID.randomUUID().toString; s"foo\0${uid}"
val uid = java.util.UUID.randomUUID().toString; s"foo\0" + uid

StackTrace:

java.lang.StringIndexOutOfBoundsException: String index out of range: 5
	at java.lang.String.charAt(String.java:658)
	at scala.collection.immutable.StringOps$.apply$extension(StringOps.scala:39)
	at scala.StringContext$.treatEscapes(StringContext.scala:206)
	at scala.StringContext$$anonfun$s$1.apply(StringContext.scala:90)
	at scala.StringContext$$anonfun$s$1.apply(StringContext.scala:90)
	at scala.StringContext.standardInterpolator(StringContext.scala:120)
	at scala.StringContext.s(StringContext.scala:90)
	at .<init>(<console>:10)
	at .<clinit>(<console>)
	at .<init>(<console>:7)
	at .<clinit>(<console>)
	at $print(<console>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:731)
	at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:980)
	at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:570)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:601)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:565)
	at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:745)
	at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:790)
	at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:702)
	at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:566)
	at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:573)
	at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:576)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:867)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
	at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
	at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@scabug
Copy link
Author

scabug commented Feb 7, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7094?orig=1
Reporter: Andrey Kouznetsov (wb)
Affected Versions: 2.10.0
Duplicates #6631

@scabug
Copy link
Author

scabug commented Feb 8, 2013

@ViniciusMiana said:
Problem seem to be fixed:
Welcome to Scala version 2.10.1-20130117-094550-1a63cf8b9b (OpenJDK Server VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.

scala> s"foo\0${java.util.UUID.randomUUID().toString}"
res0: String = foo?b88df8a2-96ed-4f73-bf2d-7ded17c841f2

scala> s"foo\0" + java.util.UUID.randomUUID().toString
res1: String = foo?11a82998-8164-4dd4-afa1-012ea0889e7b

scala> (s"foo\0") + java.util.UUID.randomUUID().toString
res2: String = foo?cda06fd1-414f-437f-aa79-ccd12da5169d

scala> val uid = java.util.UUID.randomUUID().toString; s"foo\0${uid}"
uid: String = ae01e1e2-1ead-4d72-b754-f7d3ebedc495
res3: String = foo?ae01e1e2-1ead-4d72-b754-f7d3ebedc495

scala> val uid = java.util.UUID.randomUUID().toString; s"foo\0" + uid
uid: String = dfcc4bb0-32a9-42ee-a1b6-b393d4471792
res4: String = foo?dfcc4bb0-32a9-42ee-a1b6-b393d4471792

scala> val uid = java.util.UUID.randomUUID().toString; s"fo\no\0" + uid
uid: String = 629683e6-aa0b-46a7-8009-ef4f78831ef0
res5: String =
fo
o?629683e6-aa0b-46a7-8009-ef4f78831ef0

scala> val uid = java.util.UUID.randomUUID().toString; s"fo\no\0" + uid
uid: String = 02a71e1e-dd02-4953-aa5e-0c35559b6da6
res6: String =
fo
o?02a71e1e-dd02-4953-aa5e-0c35559b6da6

@scabug
Copy link
Author

scabug commented Feb 8, 2013

@JamesIry said:
I can reproduce under 2.10.0 but not under the current 2.10.x branch (soon to be 2.10.1-RC1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants