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
scala.util.matching.regex.replaceAllIn(String, (Match) => String) escapes backslashes #4750
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4750?orig=1
|
Jeff Tsay (jctsay) said: ... In the case of regex.replaceAllIn(String, (Match) => String) the API user probably wouldn't be aware of this behavior and it would probably not be the common case to want to have replaceAllIn() to do processing of the returned string (for $1 references etc.). So I think replaceAllIn() should call Matcher.quoteReplacement() on the String result before passing it to Matcher.appendReplacement(). Alternatively, the behavior can be left the same, and the user required to call Matcher.quoteReplacement() himself, but then the documentation for replaceAllIn(String, (Match) => String) should be augmented to mention the string processing that is done by appendReplacement(). |
@dcsobral said: |
@dcsobral said: The behavior makes sense for the other replace methods, and I think it would be more surprising to have this one behave differently than having it behave like it does. The workaround is not too inconvenient, and proper documentation goes a long way towards addressing the issue. |
@dcsobral said: |
@dcsobral said: Fixed on master with commit 479dd13148c380619d3e9156ef1913467decc05c. |
scala.util.matching.regex.replaceAllIn(String, (Match) => String) seems to escape backslashes in the string to be operated on. The attached example shows how scala.util.matching.regex.replaceAllIn(String, (Match) => String) has different behavior compared to scala.util.matching.regex.replaceAllIn(String, String). In my environment I get the following output:
c:\projects\j2s\Java2Scala>scala RegexTest
rs = 'public foo "gh\dooh"'
r1 = '"gh\dooh"'
r2 = '"gh\dooh"'
But I would have expected r1 and r2 to be identical.
The text was updated successfully, but these errors were encountered: