summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-03 15:41:44 +0200
committerSamuel Holland <samuel@sholland.org>2018-05-03 19:15:09 -0500
commit8ef4a2f2f0216d5bd716d990dbf89b80868b9103 (patch)
treeb72aca93641100adec13bcbe66876f18376aee32 /app/src/main/java/com
parent3bbffa22a37cc811839c38d3dbac88f377041f6c (diff)
config: loosen parser to match reality
Mid-line comments, mixed case.
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r--app/src/main/java/com/wireguard/config/Attribute.java4
-rw-r--r--app/src/main/java/com/wireguard/config/Config.java10
2 files changed, 9 insertions, 5 deletions
diff --git a/app/src/main/java/com/wireguard/config/Attribute.java b/app/src/main/java/com/wireguard/config/Attribute.java
index 2caa9fb2..98e9fcbc 100644
--- a/app/src/main/java/com/wireguard/config/Attribute.java
+++ b/app/src/main/java/com/wireguard/config/Attribute.java
@@ -42,7 +42,7 @@ enum Attribute {
static {
KEY_MAP = new HashMap<>(Attribute.values().length);
for (final Attribute key : Attribute.values()) {
- KEY_MAP.put(key.token, key);
+ KEY_MAP.put(key.token.toLowerCase(), key);
}
}
@@ -67,7 +67,7 @@ enum Attribute {
}
public static Attribute match(final CharSequence line) {
- return KEY_MAP.get(SEPARATOR_PATTERN.split(line)[0]);
+ return KEY_MAP.get(SEPARATOR_PATTERN.split(line)[0].toLowerCase());
}
public static InetAddress parseIPString(final String address) {
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java
index f2bcd2fe..2b6b0705 100644
--- a/app/src/main/java/com/wireguard/config/Config.java
+++ b/app/src/main/java/com/wireguard/config/Config.java
@@ -41,12 +41,16 @@ public class Config {
String line;
boolean inInterfaceSection = false;
while ((line = reader.readLine()) != null) {
- if (line.isEmpty() || line.startsWith("#"))
+ final int commentIndex = line.indexOf('#');
+ if (commentIndex != -1)
+ line = line.substring(0, commentIndex);
+ line = line.trim();
+ if (line.isEmpty())
continue;
- if ("[Interface]".equals(line)) {
+ if ("[Interface]".toLowerCase().equals(line.toLowerCase())) {
currentPeer = null;
inInterfaceSection = true;
- } else if ("[Peer]".equals(line)) {
+ } else if ("[Peer]".toLowerCase().equals(line.toLowerCase())) {
currentPeer = new Peer();
config.peers.add(currentPeer);
inInterfaceSection = false;