Skip to content

Commit 2bb8944

Browse files
kuishou68pojian68
andcommitted
fix: add validation for multi-character separators in split() (Closes #14649)
Co-authored-by: kuishou68 <54054995+kuishou68@users.noreply.github.com> Co-authored-by: pojian68 <232320289+pojian68@users.noreply.github.com> Signed-off-by: lingxiu58 <86288566+lingxiu58@users.noreply.github.com>
1 parent 6c04620 commit 2bb8944

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

strings/split.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ def split(string: str, separator: str = " ") -> list:
1717
1818
>>> split(";abbb;;c;", separator=';')
1919
['', 'abbb', '', 'c', '']
20+
21+
>>> split("a--b--c", separator="--")
22+
Traceback (most recent call last):
23+
...
24+
ValueError: separator must be a single character
25+
26+
>>> split("hello world", separator="")
27+
Traceback (most recent call last):
28+
...
29+
ValueError: separator must be a single character
2030
"""
2131

32+
if len(separator) != 1:
33+
raise ValueError("separator must be a single character")
34+
2235
split_words = []
2336

2437
last_index = 0

0 commit comments

Comments
 (0)