summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-12-03 08:51:44 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-12-04 09:41:31 -0800
commitbea2ffc7da7bcd304a137e89c4d43292e30c6273 (patch)
treea89a1cc91317f2f20c5aa4dcc0e27aa4e6ceab6a
parent313c4b7d8e9a31da8356a7c0e04d1bbd2c74a42d (diff)
downloadmeson-bea2ffc7da7bcd304a137e89c4d43292e30c6273.tar.gz
interpreter: validate argument to string.split() for empty string
The underlying Python implementation throws in this case, and I'm not sure what the correct result here would be if we allowed it. Convert to None and don't split? Split every character? I've gone with throwing InvalidArguments, which maintains the current behavior of "doesn't work" but with a nicer output. Any other change would require a FeatureNew anyway, and can wait till 1.11. Fixes: #15335
-rw-r--r--mesonbuild/interpreter/primitives/string.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/mesonbuild/interpreter/primitives/string.py b/mesonbuild/interpreter/primitives/string.py
index 190e82a39..2adc58d34 100644
--- a/mesonbuild/interpreter/primitives/string.py
+++ b/mesonbuild/interpreter/primitives/string.py
@@ -108,7 +108,10 @@ class StringHolder(ObjectHolder[str]):
@typed_pos_args('str.split', optargs=[str])
@InterpreterObject.method('split')
def split_method(self, args: T.Tuple[T.Optional[str]], kwargs: TYPE_kwargs) -> T.List[str]:
- return self.held_object.split(args[0])
+ delimiter = args[0]
+ if delimiter == '':
+ raise InvalidArguments('str.split() delimitier must not be an empty string')
+ return self.held_object.split(delimiter)
@noKwargs
@typed_pos_args('str.strip', optargs=[str])