You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/03/20 14:21:22 UTC

[sling-org-apache-sling-repoinit-parser] branch master updated: SLING-9227 - clarify escaped backslashes in quoted strings

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git


The following commit(s) were added to refs/heads/master by this push:
     new c196864  SLING-9227 - clarify escaped backslashes in quoted strings
c196864 is described below

commit c196864f43ef0633d84e60dfaea6ae74866a1a5f
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Mar 20 15:21:08 2020 +0100

    SLING-9227 - clarify escaped backslashes in quoted strings
---
 src/main/javacc/RepoInitGrammar.jjt                                  | 5 ++++-
 .../org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java     | 1 +
 src/test/resources/testcases/test-61-output.txt                      | 5 ++++-
 src/test/resources/testcases/test-61.txt                             | 5 ++++-
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index a6bbb73..0e94eac 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -662,7 +662,10 @@ String quotedString() :
     ( str = <QUOTED> )
     {
         // Remove escaping backslash for double quotes
-        return str.image.replaceAll("\\\\\"", "\"");
+        return str.image
+            .replaceAll("\\\\\"", "\"")
+            .replaceAll("\\\\\\\\", "\\\\")
+        ;
     }
 }
 
diff --git a/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java b/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
index c5c5628..b7f5fe6 100644
--- a/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
@@ -76,6 +76,7 @@ public class ParsingErrorsTest {
             add(new Object[] { "disable service user foo \"missing colon\"", ParseException.class });
             add(new Object[] { "disable service user foo : missing start quote\"", ParseException.class });
             add(new Object[] { "disable service user foo : \"missing end quote", ParseException.class });
+            add(new Object[] { "disable service user foo: \"Unescaped quoted single backslash \"\\\" fails", ParseException.class });
 
             // SLING-7066 default mixin is not supported
             add(new Object[] { "create path (sling:Folder mixin mix:A) /var/foo", ParseException.class });
diff --git a/src/test/resources/testcases/test-61-output.txt b/src/test/resources/testcases/test-61-output.txt
index 4375388..ac995c0 100644
--- a/src/test/resources/testcases/test-61-output.txt
+++ b/src/test/resources/testcases/test-61-output.txt
@@ -1,2 +1,5 @@
 DisableServiceUser svcA : This message explains why it's disabled.  Whitespace   is  preserved.
-DisableServiceUser svcB : Testing escaped double "quote" in this string.
\ No newline at end of file
+DisableServiceUser svcB : Testing escaped double "quote" in this string.
+DisableServiceUser svcC : Testing escaped backslash \ in this string.
+DisableServiceUser svcD : Testing quoted escaped backslash "\" in this string.
+DisableServiceUser svcE : Testing unescaped single backslash \ in this string.
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-61.txt b/src/test/resources/testcases/test-61.txt
index 72b2324..24284ce 100644
--- a/src/test/resources/testcases/test-61.txt
+++ b/src/test/resources/testcases/test-61.txt
@@ -1,3 +1,6 @@
 # Test "disable service user" statements
 disable service user svcA : "This message explains why it's disabled.  Whitespace   is  preserved."
-disable service user svcB : "Testing escaped double \"quote\" in this string."
\ No newline at end of file
+disable service user svcB : "Testing escaped double \"quote\" in this string."
+disable service user svcC : "Testing escaped backslash \\ in this string."
+disable service user svcD : "Testing quoted escaped backslash \"\\\" in this string."
+disable service user svcE : "Testing unescaped single backslash \ in this string."
\ No newline at end of file