Skip to content

Reject multi-character split separators - #15242

Closed
Rokesh2008 wants to merge 1 commit into
TheAlgorithms:masterfrom
Rokesh2008:fix/split-multichar-separator
Closed

Reject multi-character split separators#15242
Rokesh2008 wants to merge 1 commit into
TheAlgorithms:masterfrom
Rokesh2008:fix/split-multichar-separator

Conversation

@Rokesh2008

Copy link
Copy Markdown

Fixes #14649.

The custom strings.split.split implementation compares one input character at a time, so a multi-character separator is silently ignored and returns incorrect output. This PR:

  • raises ValueError("separator must be a single character") for invalid separators
  • preserves existing single-character separator behaviour
  • adds a doctest and pytest regression coverage

Tests:

  • python -m pytest tests/test_split.py -q (2 passed)
  • python -m doctest strings/split.py
  • git diff --check

Comment thread tests/test_split.py
@@ -0,0 +1,12 @@
import pytest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doctests are good enough. We do not need any tests added here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

split silently returns wrong result for multi-character separators

2 participants