android: Escape backslashes in settings values
authorTobias Brunner <tobias@strongswan.org>
Tue, 13 Jun 2017 15:42:33 +0000 (17:42 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 3 Jul 2017 08:27:51 +0000 (10:27 +0200)
For usernames that use domain specifiers.

src/frontends/android/app/src/main/java/org/strongswan/android/utils/SettingsWriter.java
src/frontends/android/app/src/test/java/org/strongswan/android/test/SettingsWriterTest.java

index 01c0ab8..dd77490 100644 (file)
@@ -118,7 +118,7 @@ public class SettingsWriter
         */
        private String escapeValue(String value)
        {
-               return value.replace("\"", "\\\"");
+               return value.replace("\\", "\\\\").replace("\"", "\\\"");
        }
 
        /**
index aaa880c..cfad01d 100644 (file)
@@ -95,7 +95,8 @@ public class SettingsWriterTest
                SettingsWriter writer = new SettingsWriter();
                writer.setValue("key", "val\"ue");
                writer.setValue("nl", "val\nue");
-               assertEquals("serialized", "key=\"val\\\"ue\"\nnl=\"val\nue\"\n", writer.serialize());
+               writer.setValue("bs", "val\\ue");
+               assertEquals("serialized", "key=\"val\\\"ue\"\nnl=\"val\nue\"\nbs=\"val\\\\ue\"\n", writer.serialize());
        }
 
        @Test