Skip to content

fix: reject multi-character separators in split() (Closes #14649)#14751

Open
kuishou68 wants to merge 1 commit into
TheAlgorithms:masterfrom
kuishou68:fix/issue-14649-split-multichar
Open

fix: reject multi-character separators in split() (Closes #14649)#14751
kuishou68 wants to merge 1 commit into
TheAlgorithms:masterfrom
kuishou68:fix/issue-14649-split-multichar

Conversation

@kuishou68
Copy link
Copy Markdown

Describe your change

This PR fixes the bug where the custom split function in strings/split.py silently returns the unsplit string when a multi-character separator is provided.

The function was comparing each individual character against the full separator string, so multi-character separators like "--" were never matched.

Fix: Added validation at the beginning of the function to raise a ValueError when separator is not exactly one character. This matches the expected behavior described in the issue.

Closes #14649

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Closes split silently returns wrong result for multi-character separators #14649".

…heAlgorithms#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>
@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

split silently returns wrong result for multi-character separators

1 participant