Merged
Conversation
Liquidscroll
approved these changes
Sep 4, 2024
Liquidscroll
left a comment
There was a problem hiding this comment.
This looks good to me! I think it makes sense to return the entire input text when the substring is empty, I think it's pretty logical.
DarrenSunandar
approved these changes
Sep 6, 2024
DarrenSunandar
left a comment
There was a problem hiding this comment.
This pull request is well-structured and logical change made. The early check for an empty substring ensures that the function won't crash. Also, nice to ensures that when the substring is empty, the original string is returned, preventing an infinite loop.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
While creating unit tests, I identified a bug in the
replace_allfunction which causes an infinite loop if thesubstrargument is an empty string. I added a check at the beginning of the function which detects if the sub-string is empty. If so, the input stringtextis returned.There are multiple ways to handle this edge case. One is to throw an exception, another is to return an empty string. I believe the most logical response it to return the unaltered input string as it shows to the user that no action will be taken with an empty sub-string.
This is not a breaking change as the current behavior always results in a program crash.
Type of change
How Has This Been Tested?
I added an extra line of testing to
test_text.cppwhich uses an empty string as thesubstrargument. It runs as expected. In a separate pull request, I have created unit testing forreplace_allwhich also tests this function's edge cases.Testing Checklist
Checklist