Prevent regex metacharacter crashes in CamelCase.toCamelCase - #103
Closed
krotname wants to merge 1 commit into
Closed
Prevent regex metacharacter crashes in CamelCase.toCamelCase#103krotname wants to merge 1 commit into
krotname wants to merge 1 commit into
Conversation
Owner
Author
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.
Motivation
toCamelCaseusedString.replaceFirstwith the first character as a regex/replacement, which can throwPatternSyntaxExceptionorIllegalArgumentExceptionfor inputs starting with metacharacters and crashes onnullinput.Description
kyu6.CamelCase.toCamelCaseto return an empty string fornullor empty input.replaceFirstcall with literal substring concatenation:s.substring(0,1).toUpperCase(Locale.ROOT) + s.substring(1)to avoid regex/replacement parsing of the first character.src/test/java/kyu6/CamelCaseTest.javathat assert correct behavior for inputs containing regex/replacement metacharacters and fornullinput.Testing
mvn -q -Dtest=CamelCaseTest testand it passed.mvn -q testand it completed successfully for this change.git diff --checkto ensure no whitespace or patch issues (no problems reported).Codex Task