Skip to content

Prevent regex metacharacter crashes in CamelCase.toCamelCase - #103

Closed
krotname wants to merge 1 commit into
mainfrom
codex/fix-camelcase.tocamelcase-regex-issue
Closed

Prevent regex metacharacter crashes in CamelCase.toCamelCase#103
krotname wants to merge 1 commit into
mainfrom
codex/fix-camelcase.tocamelcase-regex-issue

Conversation

@krotname

@krotname krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Motivation

  • toCamelCase used String.replaceFirst with the first character as a regex/replacement, which can throw PatternSyntaxException or IllegalArgumentException for inputs starting with metacharacters and crashes on null input.

Description

  • Add a null/empty guard in kyu6.CamelCase.toCamelCase to return an empty string for null or empty input.
  • Replace the regex-based replaceFirst call with literal substring concatenation: s.substring(0,1).toUpperCase(Locale.ROOT) + s.substring(1) to avoid regex/replacement parsing of the first character.
  • Add regression tests in src/test/java/kyu6/CamelCaseTest.java that assert correct behavior for inputs containing regex/replacement metacharacters and for null input.

Testing

  • Ran the CamelCase unit test: mvn -q -Dtest=CamelCaseTest test and it passed.
  • Ran the full test suite: mvn -q test and it completed successfully for this change.
  • Ran git diff --check to ensure no whitespace or patch issues (no problems reported).

Codex Task

@krotname

krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the validated combined merge in #115: #115

@krotname krotname closed this Aug 1, 2026
@krotname
krotname deleted the codex/fix-camelcase.tocamelcase-regex-issue branch August 1, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant