From 911cd5e0e5da46cddf8541785d8f3731a8859976 Mon Sep 17 00:00:00 2001 From: Igor Bogoslavskyi Date: Mon, 16 Mar 2020 11:43:02 +0100 Subject: [PATCH] Fix flag parsing for /U flag (#678) --- plugin/utils/flag.py | 6 +++--- tests/test_flag.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugin/utils/flag.py b/plugin/utils/flag.py index d9df841a..23f97fa3 100644 --- a/plugin/utils/flag.py +++ b/plugin/utils/flag.py @@ -159,6 +159,9 @@ def __init__(self): def from_unparsed_string(self, chunk): """Parse an unknown string into body and prefix.""" chunk = chunk.strip() + if not Flag.indicates_flag(chunk): + # This is not a valid flag, so reset all values to default. + return Flag.Builder() for prefix in Flag.SEPARABLE_PREFIXES: if chunk.startswith(prefix): self.__prefix = prefix @@ -171,9 +174,6 @@ def from_unparsed_string(self, chunk): # We did not find any separable prefix, so it's all body. if not self.__body: self.__body = chunk - if not Flag.indicates_flag(self.__body): - # This is not a valid flag, so reset all values to default. - self.__init__() return self def with_body(self, body): diff --git a/tests/test_flag.py b/tests/test_flag.py index 2cb6f4a1..e57072cc 100644 --- a/tests/test_flag.py +++ b/tests/test_flag.py @@ -66,6 +66,11 @@ def test_builder(self): self.assertEqual(Flag("-I", "world"), flag3) flag4 = Flag.Builder().from_unparsed_string('-include world').build() self.assertEqual(Flag("-include", "world", " "), flag4) + # Check that we don't trigger on /U flag. + import platform + if platform.system() != "Windows": + flag5 = Flag.Builder().from_unparsed_string('/User/blah').build() + self.assertEqual(Flag("", "", ""), flag5) def test_builder_invalid(self): """Test tokenizing invalid flags."""