From 2bb8944d4580a0704a3f090acc3d1ebabba0b7d6 Mon Sep 17 00:00:00 2001 From: Cocoon-Break <54054995+kuishou68@users.noreply.github.com> Date: Tue, 2 Jun 2026 10:44:54 +0800 Subject: [PATCH] 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> --- strings/split.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/strings/split.py b/strings/split.py index ed194ec69c2f..7c5b32df5941 100644 --- a/strings/split.py +++ b/strings/split.py @@ -17,8 +17,21 @@ def split(string: str, separator: str = " ") -> list: >>> split(";abbb;;c;", separator=';') ['', 'abbb', '', 'c', ''] + + >>> split("a--b--c", separator="--") + Traceback (most recent call last): + ... + ValueError: separator must be a single character + + >>> split("hello world", separator="") + Traceback (most recent call last): + ... + ValueError: separator must be a single character """ + if len(separator) != 1: + raise ValueError("separator must be a single character") + split_words = [] last_index = 0