Skip to content

Commit

Permalink
Fix flag parsing for /U flag (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
niosus authored Mar 16, 2020
1 parent 9d0af0a commit 911cd5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugin/utils/flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 911cd5e

Please sign in to comment.