fix: reject multi-character separators in split() (Closes #14649) by kuishou68 · Pull Request #14751 · TheAlgorithms/Python
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".