Skip to content

Reject a trailing newline in all parsers - #146

Open
gnutix wants to merge 2 commits into
brick:mainfrom
gnutix:fix/parse-trailing-newline
Open

gnutix wants to merge 2 commits into
brick:mainfrom
gnutix:fix/parse-trailing-newline

Conversation

@gnutix

@gnutix gnutix commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Item 6 of #137.

Problem

In PCRE, $ without the D modifier also matches before a final "\n", so every parser accepted one:

LocalDate::parse("2014-12-31\n"); // 2014-12-31 (same for LocalTime, LocalDateTime, ZonedDateTime, YearMonth, Year, TimeZone, …)
Period::parse("P1D\n");           // P1D
Duration::parse("PT1S\n");        // PT1S

Code that validates a string with parse() and then stores the raw string kept the newline.

Change

The D (PCRE_DOLLAR_ENDONLY) modifier is added to the three regexes that do the parsing: PatternParser::parse(), which all the ISO parsers go through, Period::parse() and Duration::parse().

A "\n" case is added to the parse-failure providers of every class with a parse() method. LocalDateTest had no such test, so it gets testParseInvalidStringThrowsException().

CI

The last commit is #133's Install tzdata-legacy in CI, cherry-picked: the ubuntu-26.04 runner image no longer ships legacy zone names such as CET and Asia/Rangoon, so PHPUnit fails on every branch based on main (#143 and #144 too). It is the same change as in #133, so it merges cleanly whichever lands first.

🤖 Generated with Claude Code (Opus 5.5)

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.24%. Comparing base (81915a3) to head (c642928).

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #146   +/-   ##
=========================================
  Coverage     99.24%   99.24%           
  Complexity     1143     1143           
=========================================
  Files            48       48           
  Lines          2517     2517           
=========================================
  Hits           2498     2498           
  Misses           19       19           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

joelbutcher and others added 2 commits November 9, 2026 09:46
ubuntu-latest now points to Ubuntu 26.04, which no longer installs
tzdata-legacy. Without it, PHP doesn't know legacy time zone names such as
CET and Asia/Rangoon, which the tests use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FQhVM8scWxQrMU3djngjpv
(cherry picked from commit 1c48e3b)
Without the D modifier, PCRE's $ also matches before a final newline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gnutix
gnutix force-pushed the fix/parse-trailing-newline branch from 94cad78 to c642928 Compare November 9, 2026 08:46
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.

2 participants