Skip to content

Commit 7695128

Browse files
committed
[build-script] Use more strict regex for --clang-compiler-version argument
1 parent 90ed14d commit 7695128

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

utils/swift_build_support/swift_build_support/arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def type_clang_compiler_version(string):
7878
7979
Support only "MAJOR.MINOR.PATCH" format.
8080
"""
81-
m = re.match(r'([0-9]*)\.([0-9]*)\.([0-9]*)', string)
81+
m = re.match(r'^([0-9]+)\.([0-9]+)\.([0-9]+)$', string)
8282
if m is not None:
8383
return m.group(1, 2, 3)
8484
raise argparse.ArgumentTypeError(

utils/swift_build_support/tests/test_arguments.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,18 @@ def test_clang_compiler_version(self):
5050
argparse.ArgumentTypeError,
5151
argtype.clang_compiler_version,
5252
"1.beta2.3")
53-
self.assertEqual(
54-
argtype.clang_compiler_version("1.2.preview3"),
55-
("1", "2", ""))
56-
self.assertEqual(
57-
argtype.clang_compiler_version("1.2.3-rc4"),
58-
("1", "2", "3"))
53+
self.assertRaises(
54+
argparse.ArgumentTypeError,
55+
argtype.clang_compiler_version,
56+
"1.2.preview3")
57+
self.assertRaises(
58+
argparse.ArgumentTypeError,
59+
argtype.clang_compiler_version,
60+
"1.2.3-rc4")
61+
self.assertRaises(
62+
argparse.ArgumentTypeError,
63+
argtype.clang_compiler_version,
64+
"1..2")
5965

6066
def test_executable(self):
6167
python = sys.executable

0 commit comments

Comments
 (0)