You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by fp...@apache.org on 2020/04/10 04:41:15 UTC
[shiro] branch master updated: [SHIRO-530] INI parser does not
properly handled backslashes at end of values
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 b50b829 [SHIRO-530] INI parser does not properly handled backslashes at end of values
new 8b46c8a Merge pull request #210 from bmhm/SHIRO-530-alt
b50b829 is described below
commit b50b829a285b106666b688a4b69a3ebee94f51b4
Author: Benjamin Marwell <bm...@gmail.com>
AuthorDate: Wed Apr 1 07:24:19 2020 +0200
[SHIRO-530] INI parser does not properly handled backslashes at end of values
- Do not skip escape characters for the value (new behaviour demanded by SHIRO-530).
- rearrange and comment tests to reflect old and new, desired behaviour.
Signed-off-by: Benjamin Marwell <bm...@gmail.com>
---
.../src/main/java/org/apache/shiro/config/Ini.java | 2 +-
.../groovy/org/apache/shiro/config/IniTest.groovy | 42 +++++++++++++++++++---
2 files changed, 38 insertions(+), 6 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 1c42f0e..7993619 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
@@ -587,7 +587,7 @@ public class Ini implements Map<String, Ini.Section> {
} else {
if (valueBuffer.length() == 0 && isKeyValueSeparatorChar(c) && !isCharEscaped(line, i)) {
//swallow the separator chars before we start building the value
- } else if (!isCharEscaped(line, i)){
+ } else {
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 56bb99e..cf9ee12 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
@@ -73,6 +73,22 @@ public class IniTest {
}
@Test
+ public void testBackslash() {
+ String test = "Truth=Beauty\\\\";
+ Ini ini = new Ini();
+ ini.load(test);
+
+ assertNotNull(ini.getSections());
+ assertEquals(1, ini.getSections().size());
+
+ Ini.Section section = ini.getSections().iterator().next();
+ assertEquals(Ini.DEFAULT_SECTION_NAME, section.getName());
+ assertFalse(section.isEmpty());
+ assertEquals(1, section.size());
+ assertEquals("Beauty\\\\", section.get("Truth"));
+ }
+
+ @Test
public void testSplitKeyValue() {
String test = "Truth Beauty";
String[] kv = Ini.Section.splitKeyValue(test);
@@ -119,24 +135,40 @@ public class IniTest {
assertEquals("Truth", kv[0]);
assertEquals("Beauty", kv[1]);
+ // Escape characters are to be removed from the key.
+ // This is different behaviour compared to the XML config.
test = "Tru\\th=Beauty";
kv = Ini.Section.splitKeyValue(test);
assertEquals("Truth", kv[0]);
assertEquals("Beauty", kv[1]);
- test = "Truth\\=Beauty";
+ // SHIRO-530: Keep backslashes in value.
+ test = "Truth=Beau\\ty";
kv = Ini.Section.splitKeyValue(test);
assertEquals("Truth", kv[0]);
- assertEquals("Beauty", kv[1]);
+ assertEquals("Beau\\ty", kv[1]);
- test = "Truth=Beau\\ty";
+ // SHIRO-530: Keep backslashes in value.
+ test = "Truth=Beauty\\";
kv = Ini.Section.splitKeyValue(test);
assertEquals("Truth", kv[0]);
- assertEquals("Beauty", kv[1]);
+ assertEquals("Beauty\\", kv[1]);
- test = "Truth=Beauty\\";
+ // SHIRO-530: Keep backslashes in value.
+ test = "Truth= \\ Beauty\\";
kv = Ini.Section.splitKeyValue(test);
assertEquals("Truth", kv[0]);
+ assertEquals("\\ Beauty\\", kv[1]);
+ }
+
+ /**
+ * Tests if an escaped separator char will not be recognized as such.
+ */
+ @Test
+ public void testSplitKeyValueEscapedEquals() {
+ String test = "Truth\\=Beauty";
+ String[] kv = Ini.Section.splitKeyValue(test);
+ assertEquals("Truth", kv[0]);
assertEquals("Beauty", kv[1]);
}