Skip to content

Conversation

ppkarwasz
Copy link
Contributor

This PR fixes edge cases involving the apostrophe (') in pattern literals. Previously, certain inputs produced unintended escaped apostrophes ('') at fragment boundaries or misinterpreted doubled quotes inside quoted blocks.

What’s changed

  • Parsing: Correctly interprets '' as a literal apostrophe inside quoted sections.
  • Merging: When concatenating pattern fragments, if the left ends with ' and the right starts with ', we now drop the left closing quote and the right opening quote to keep a single continuous quoted block, avoiding an unintended literal ''.
  • Tests: Added comprehensive cases covering parsing and boundary merges.

Rationale

DateTimeFormatter uses '...' to denote literals and '' to escape a literal apostrophe. When two quoted literal blocks are concatenated naïvely, a ...''... boundary can be produced, which DateTimeFormatter reads as a literal apostrophe, not close+open delimiters.

Closes #3930.

Checklist

Before we can review and merge your changes, please go through the checklist below. If you're still working on some items, feel free to submit your pull request as a draft—our CI will help guide you through the remaining steps.

✅ Required checks

  • License: I confirm that my changes are submitted under the Apache License, Version 2.0.

  • Commit signatures: All commits are signed and verifiable. (See GitHub Docs on Commit Signature Verification).

  • Code formatting: The code is formatted according to the project’s style guide.

    How to check and fix formatting
    • To check formatting: ./mvnw spotless:check
    • To fix formatting: ./mvnw spotless:apply

    See the build instructions for details.

  • Build & Test: I verified that the project builds and all unit tests pass.

    How to build the project

    Run: ./mvnw verify

    See the build instructions for details.

🧪 Tests (select one)

  • I have added or updated tests to cover my changes.
  • No additional tests are needed for this change.

📝 Changelog (select one)

  • I added a changelog entry in src/changelog/.2.x.x. (See Changelog Entry File Guide).
  • This is a trivial change and does not require a changelog entry.

This PR fixes edge cases involving the apostrophe (`'`) in pattern literals. Previously, certain inputs produced unintended escaped apostrophes (`''`) at fragment boundaries or misinterpreted doubled quotes inside quoted blocks.

## What’s changed

* **Parsing:** Correctly interprets `''` as a literal apostrophe **inside** quoted sections.
* **Merging:** When concatenating pattern fragments, if the left ends with `'` and the right starts with `'`, we now drop the left closing quote and the right opening quote to keep a single continuous quoted block, avoiding an unintended literal `''`.
* **Tests:** Added comprehensive cases covering parsing and boundary merges.

## Rationale

`DateTimeFormatter` uses `'...'` to denote literals and `''` to escape a literal apostrophe. When two quoted literal blocks are concatenated naïvely, a `...''...` boundary can be produced, which `DateTimeFormatter` reads as a **literal apostrophe**, not close+open delimiters.

Closes #3930.
Copy link

@tanmaybaid tanmaybaid left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this.

@vy vy merged commit 9b9a0d4 into 2.x Sep 18, 2025
11 checks passed
@vy vy deleted the fix/3930_date-converter branch September 18, 2025 17:49
@github-project-automation github-project-automation bot moved this from To triage to Done in Log4j bug tracker Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

DatePatternConverter incorrectly converting date pattern since Log4J 2.25.0
3 participants