[ https://issues.apache.org/jira/browse/GROOVY-7564?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14725500#comment-14725500 ]
Thibault Kruse commented on GROOVY-7564: ---------------------------------------- I think we still don't understand each other. InvokerHelper has this line, in the snippet to escape Strings for displaying hyphenated strings: {code} arg = arg.replaceAll("\\\\", "\\\\"); // backslash {code} But this line does not escape backslashes. This line does effectively nothing, it replaces any single slash with a single slash: {code} String source = "a\\b"; // the replaceAll call does not change the original string. It replaces any one slash with one slash. assertEquals(source, source.replaceAll("\\\\", "\\\\")); {code} This is a pecularity of replaceAll that the second argument, though not being a regex, still has special backslash semantics in the replacement code (see http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#replaceAll%28java.lang.String%29 : "Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string." ) So the code of InvokerHelper contains a line that has no effect. Can we agree on this first, maybe? You can check this with a unit test: {code} @Test public void testEscaping() { String source = "a\\b"; assertEquals(source, source.replaceAll("\\\\", "\\\\")); } {code} Once we agree that this line in InvokerHelper does nothing, we can maybe look further if we should: - keep that line - remove that line - exchange it with a line that actually does something > InvokerHelper verbose printing wrongly escapes backslashes > ----------------------------------------------------------- > > Key: GROOVY-7564 > URL: https://issues.apache.org/jira/browse/GROOVY-7564 > Project: Groovy > Issue Type: Bug > Reporter: Thibault Kruse > Priority: Minor > > Tor reproduce: > {code} > groovy:000> InvokerHelper.format('a\\b', true, -1) > ===> 'a\b' > {code} > Should be > {code}'a\\b'{code} > See https://github.com/apache/incubator-groovy/pull/96 -- This message was sent by Atlassian JIRA (v6.3.4#6332)