From eb61d9ef4c270826eaf19fbd8ca8a3b353912968 Mon Sep 17 00:00:00 2001 From: Andrey Pangin Date: Wed, 4 Sep 2019 19:02:33 +0300 Subject: [PATCH] ConfigParser should allow extra spaces --- src/one/nio/config/ConfigParser.java | 6 +++--- test/one/nio/config/ConfigParserTest.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/one/nio/config/ConfigParser.java b/src/one/nio/config/ConfigParser.java index d22bb9d..81e60b2 100644 --- a/src/one/nio/config/ConfigParser.java +++ b/src/one/nio/config/ConfigParser.java @@ -329,7 +329,7 @@ private Object parseScalar(Class type, String value) { private void registerReference(Object ref) { if (hasTail() && line.charAt(indent) == '&') { - Object prev = references.put(line.substring(indent + 1), ref); + Object prev = references.put(line.substring(indent + 1).trim(), ref); if (prev != null) { throw new IllegalArgumentException("Duplicate reference: " + line); } @@ -339,7 +339,7 @@ private void registerReference(Object ref) { private Object parseReference() { if (hasTail() && line.charAt(indent) == '*') { - Object ref = references.get(line.substring(indent + 1)); + Object ref = references.get(line.substring(indent + 1).trim()); if (ref == null) { throw new IllegalArgumentException("No such reference: " + line); } @@ -394,7 +394,7 @@ private void skipSpaces(int from) { } private String tail() { - String result = indent >= 0 ? line.substring(indent) : ""; + String result = indent >= 0 ? line.substring(indent).trim() : ""; indent = -1; return result; } diff --git a/test/one/nio/config/ConfigParserTest.java b/test/one/nio/config/ConfigParserTest.java index 2f4fb8e..a7afccb 100644 --- a/test/one/nio/config/ConfigParserTest.java +++ b/test/one/nio/config/ConfigParserTest.java @@ -47,16 +47,16 @@ public class ConfigParserTest { " - port: 9443\n" + " ssl: *id1\n" + " - port: 80\n" + - " backlog: 10000\n" + + " backlog: 10000 \n" + " deferAccept: false\n" + " recvBuf: 32k\n" + " sendBuf: 1M\n" + "\n" + "virtualHosts:\n" + " admin: admin.example.com\n" + - " default: &id2\n" + - " - example.com\n" + - " - www.example.com\n" + + " default: &id2 \n" + + " - example.com\n" + + " - www.example.com \n" + " invalid: *id2\n"; @Test