From 0150e336e584b39aeaca817223cb9af2ad8db016 Mon Sep 17 00:00:00 2001 From: mithunbabbira Date: Mon, 20 Jul 2026 10:24:20 +0530 Subject: [PATCH 1/2] fix: resolve #14649 - add validation for multi-char separator --- strings/split.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/strings/split.py b/strings/split.py index ed194ec69c2f..1b0d631cb4b3 100644 --- a/strings/split.py +++ b/strings/split.py @@ -17,21 +17,19 @@ def split(string: str, separator: str = " ") -> list: >>> split(";abbb;;c;", separator=';') ['', 'abbb', '', 'c', ''] - """ - - split_words = [] - last_index = 0 - for index, char in enumerate(string): - if char == separator: - split_words.append(string[last_index:index]) - last_index = index + 1 - if index + 1 == len(string): - split_words.append(string[last_index : index + 1]) - return split_words + >>> split("a--b--c", 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") + return string.split(separator) if __name__ == "__main__": from doctest import testmod testmod() + From 602264421e9c7f19959255b4aeafeb8e8f5d0c77 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Jul 2026 04:54:54 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/split.py | 1 - 1 file changed, 1 deletion(-) diff --git a/strings/split.py b/strings/split.py index 1b0d631cb4b3..fe09a92063f8 100644 --- a/strings/split.py +++ b/strings/split.py @@ -32,4 +32,3 @@ def split(string: str, separator: str = " ") -> list: from doctest import testmod testmod() -