This is an automated email from the ASF dual-hosted git repository.
fpapon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shiro.git
The following commit(s) were added to refs/heads/master by this push:
new 0c424d3 [SHIRO-684] INI parser keeps escape characters in keys and
values
new 2e3d695 Merge pull request #168 from fpapon/SHIRO-684
0c424d3 is described below
commit 0c424d37e5d542844c9ed65cf962498211d2334b
Author: Francois Papon <[email protected]>
AuthorDate: Sun Sep 22 15:15:50 2019 +0200
[SHIRO-684] INI parser keeps escape characters in keys and values
---
.../src/main/java/org/apache/shiro/config/Ini.java | 6 +++---
.../groovy/org/apache/shiro/config/IniTest.groovy | 20 ++++++++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/config/core/src/main/java/org/apache/shiro/config/Ini.java
b/config/core/src/main/java/org/apache/shiro/config/Ini.java
index d3d93cd..1c42f0e 100644
--- a/config/core/src/main/java/org/apache/shiro/config/Ini.java
+++ b/config/core/src/main/java/org/apache/shiro/config/Ini.java
@@ -561,7 +561,7 @@ public class Ini implements Map<String, Ini.Section> {
}
private static boolean isCharEscaped(CharSequence s, int index) {
- return index > 0 && s.charAt(index - 1) == ESCAPE_TOKEN;
+ return index > 0 && s.charAt(index) == ESCAPE_TOKEN;
}
//Protected to access in a test case - NOT considered part of Shiro's
public API
@@ -581,13 +581,13 @@ public class Ini implements Map<String, Ini.Section> {
if (buildingKey) {
if (isKeyValueSeparatorChar(c) && !isCharEscaped(line, i))
{
buildingKey = false;//now start building the value
- } else {
+ } else if (!isCharEscaped(line, i)){
keyBuffer.append(c);
}
} else {
if (valueBuffer.length() == 0 &&
isKeyValueSeparatorChar(c) && !isCharEscaped(line, i)) {
//swallow the separator chars before we start building
the value
- } else {
+ } else if (!isCharEscaped(line, i)){
valueBuffer.append(c);
}
}
diff --git a/config/core/src/test/groovy/org/apache/shiro/config/IniTest.groovy
b/config/core/src/test/groovy/org/apache/shiro/config/IniTest.groovy
index a17a181..56bb99e 100644
--- a/config/core/src/test/groovy/org/apache/shiro/config/IniTest.groovy
+++ b/config/core/src/test/groovy/org/apache/shiro/config/IniTest.groovy
@@ -118,6 +118,26 @@ public class IniTest {
kv = Ini.Section.splitKeyValue(test);
assertEquals("Truth", kv[0]);
assertEquals("Beauty", kv[1]);
+
+ test = "Tru\\th=Beauty";
+ kv = Ini.Section.splitKeyValue(test);
+ assertEquals("Truth", kv[0]);
+ assertEquals("Beauty", kv[1]);
+
+ test = "Truth\\=Beauty";
+ kv = Ini.Section.splitKeyValue(test);
+ assertEquals("Truth", kv[0]);
+ assertEquals("Beauty", kv[1]);
+
+ test = "Truth=Beau\\ty";
+ kv = Ini.Section.splitKeyValue(test);
+ assertEquals("Truth", kv[0]);
+ assertEquals("Beauty", kv[1]);
+
+ test = "Truth=Beauty\\";
+ kv = Ini.Section.splitKeyValue(test);
+ assertEquals("Truth", kv[0]);
+ assertEquals("Beauty", kv[1]);
}
@Test(expected = IllegalArgumentException.class)