You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2018/05/16 12:40:42 UTC
[commons-jexl] branch master updated: JEXL: fixing preparation to
add 'escaped' identifiers
This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push:
new d5943e3 JEXL: fixing preparation to add 'escaped' identifiers
d5943e3 is described below
commit d5943e3655ad622a0237451f308ca0eebf8edd4a
Author: henrib <he...@l-hbiestro.koeos.lan>
AuthorDate: Wed May 16 14:40:08 2018 +0200
JEXL: fixing preparation to add 'escaped' identifiers
---
.../java/org/apache/commons/jexl3/parser/StringParser.java | 12 +++---------
.../java/org/apache/commons/jexl3/parser/ParserTest.java | 5 +++--
2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/apache/commons/jexl3/parser/StringParser.java b/src/main/java/org/apache/commons/jexl3/parser/StringParser.java
index 375c1dd..3a02b7a 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/StringParser.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/StringParser.java
@@ -213,22 +213,16 @@ public class StringParser {
*/
public static String unescapeIdentifier(String str) {
StringBuilder strb = null;
- boolean esc = false;
if (str != null) {
int n = 0;
int last = str.length();
while (n < last) {
char c = str.charAt(n);
- if (esc) {
+ if (c == '\\') {
if (strb == null) {
strb = new StringBuilder(last);
strb.append(str.substring(0, n));
- } else {
- strb.append(c);
- }
- esc = false;
- } else if (c == '\\') {
- esc = true;
+ }
} else if (strb != null) {
strb.append(c);
}
@@ -239,7 +233,7 @@ public class StringParser {
}
/**
- * Adds a escape char ('\') where needed in a string form of an ide
+ * Adds a escape char ('\') where needed in a string form of an identifier.
* @param str the identifier un-escaped string
* @return the string with added backslash character before space, quote, double-quote and backslash
*/
diff --git a/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java b/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
index 4d0fec0..8a038fa 100644
--- a/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
+++ b/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
@@ -81,8 +81,9 @@ public class ParserTest {
public void testIdentifierEscape() {
String[] ids = new String[]{"a\\ b", "a\\ b\\ c", "a\\'b\\\"c", "a\\ \\ c"};
for(String id : ids) {
- String esc0 = StringParser.escapeIdentifier(id);
- String esc1 = StringParser.unescapeIdentifier(esc0);
+ String esc0 = StringParser.unescapeIdentifier(id);
+ Assert.assertFalse(esc0.contains("\\"));
+ String esc1 = StringParser.escapeIdentifier(esc0);
Assert.assertEquals(id, esc1);
}
}
--
To stop receiving notification emails like this one, please contact
henrib@apache.org.