Skip to content

fix(string): split and then join should be identity #2020

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

Merged
merged 1 commit into from
May 6, 2025

Conversation

peter-jerry-ye
Copy link
Collaborator

Fixes #2019

Copy link

peter-jerry-ye-code-review bot commented Apr 28, 2025

Fixed inconsistent handling of empty strings in split operation

Category
Correctness
Code Snippet
string/methods.mbt:664-670
if view.is_empty() {
IterContinue
} else {
yield_(view)
}
-> yield_(view)
Recommendation
The change to always yield the view is correct. This ensures consistent behavior with empty strings and trailing separators.
Reasoning
The previous implementation was incorrectly skipping empty strings, which made operations like split-join roundtrip impossible. The new behavior properly preserves empty segments, which is the expected behavior in string splitting operations.

Added comprehensive split-join roundtrip test cases

Category
Maintainability
Code Snippet
string/string_test.mbt:714-728
test "split and then join should be identity" {
...
}
Recommendation
Consider adding more test cases with different Unicode sequences and multi-character separators
Reasoning
While the current test cases cover basic scenarios well, adding more complex cases would help ensure the implementation remains correct for edge cases involving Unicode and multi-character separators

Duplicate test cases in string_test.mbt

Category
Maintainability
Code Snippet
string/string_test.mbt:394-401 and 482-489
Recommendation
Remove the duplicated test blocks or extract common test cases into a shared function
Reasoning
The file contains identical test blocks which increases maintenance burden and could lead to inconsistencies if only one copy is updated

@coveralls
Copy link
Collaborator

coveralls commented Apr 28, 2025

Pull Request Test Coverage Report for Build 6573

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 92.4%

Totals Coverage Status
Change from base Build 6572: 0.01%
Covered Lines: 6140
Relevant Lines: 6645

💛 - Coveralls

Copy link
Contributor

@tonyfettes tonyfettes left a comment

Choose a reason for hiding this comment

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

LGTM

@tonyfettes tonyfettes force-pushed the zihang/fix-string-split branch from 469a6d9 to 0444c8e Compare May 6, 2025 05:57
@tonyfettes tonyfettes merged commit 61ba015 into main May 6, 2025
12 checks passed
@tonyfettes tonyfettes deleted the zihang/fix-string-split branch May 6, 2025 06:36
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.

String::split has inconsistent behavior w.r.t. Python and JavaScript
3 participants