Test with comment inside quotes

This commit is contained in:
Mike Bierlee 2022-10-11 21:35:36 +03:00
parent 99a536a544
commit 6d3833cbf1

View file

@ -86,8 +86,10 @@ class KeyValueConfigFactory(
enforce!ConfigCreationException(parts.length == 2, "Missing value assignment (L" ~ index.to!string ~ "): " ~ processedLine); enforce!ConfigCreationException(parts.length == 2, "Missing value assignment (L" ~ index.to!string ~ "): " ~ processedLine);
auto value = parts[1].strip; auto value = parts[1].strip;
if (normalizeQuotedValues && (value.startsWith('"') || value.startsWith('\'')) if (normalizeQuotedValues &&
&& (value.endsWith('"') || value.endsWith('\''))) { value.length > 1 &&
(value.startsWith('"') || value.startsWith('\'')) &&
(value.endsWith('"') || value.endsWith('\''))) {
value = value[1 .. $ - 1]; value = value[1 .. $ - 1];
} }
@ -227,12 +229,14 @@ version (unittest) {
monkey = 'ape' monkey = 'ape'
human = ape human = ape
excessiveWhitespace = ' ' excessiveWhitespace = ' '
breaksWithComments = ' # Don't do this '
"); ");
assert(config.get("baboon") == "ape"); assert(config.get("baboon") == "ape");
assert(config.get("monkey") == "ape"); assert(config.get("monkey") == "ape");
assert(config.get("human") == "ape"); assert(config.get("human") == "ape");
assert(config.get("excessiveWhitespace") == " "); assert(config.get("excessiveWhitespace") == " ");
assert(config.get("breaksWithComments") == "'");
} }
} }