Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split() loses final part if it’s empty #627

Closed
danielparks opened this issue Nov 18, 2019 · 1 comment
Closed

split() loses final part if it’s empty #627

danielparks opened this issue Nov 18, 2019 · 1 comment

Comments

@danielparks
Copy link
Contributor

danielparks commented Nov 18, 2019

I ran into a few bugs:

Regex Text Limit Expected Actual Notes
"-" "a" none ["a"] ["a"]
"-" "a-" none ["a", ""] ["a"] incorrect
"-" "a--" none ["a", "", ""] ["a", ""] incorrect
"-" "a" 2 ["a"] ["a", ""] #521
"-" "a-" 2 ["a", ""] ["a", ""]
"-" "a--" 2 ["a", "-"] ["a", "-"]

See also #521: splitn incorrectly returns a trailing "" if there is one fewer part than the limit.

@danielparks
Copy link
Contributor Author

I’ve already written tests; I should have a PR ready in the next couple of days.

BurntSushi pushed a commit that referenced this issue Jan 9, 2020
Corrects `/-/.split("a-")` to return `["a", ""]` instead of `["a"]`.
(`/-/` is shorthand for `Regex::new("-").unwrap()`.)

This adds tests for both `split()` and `splitn()` covering a variety of
edge cases. One test is commented out because it is failing due to #521.
A future commit will fix it.

Note that the `split2` and `split3` tests were passing incorrectly
before this change. I have fixed them to expect the correct values.

Fixes #627
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

No branches or pull requests

1 participant