Skip to content

🐛 Fixed hyphen-separated permalink params#28129

Merged
9larsons merged 2 commits into
mainfrom
codex/fix-dated-slug-route-main
May 26, 2026
Merged

🐛 Fixed hyphen-separated permalink params#28129
9larsons merged 2 commits into
mainfrom
codex/fix-dated-slug-route-main

Conversation

@9larsons
Copy link
Copy Markdown
Contributor

@9larsons 9larsons commented May 26, 2026

fixes #28076

Summary

  • constrained generic hyphen-separated permalink params so earlier params stop at the hyphen and the final param can keep a hyphenated slug
  • kept dated permalink regression coverage and added a non-date :section-:slug case using fabricated URLs

Why this approach

path-match depends on path-to-regexp via a broad ^1.0.0 range, and the package is archived. Pinning the transitive dependency would restore the old behavior for now, but it keeps Ghost coupled to an unmaintained parser detail. This keeps the fix in Ghost by normalizing ambiguous hyphen-separated param segments before entry lookup.

Testing

  • pnpm --dir ghost/core test:single test/unit/frontend/services/data/entry-lookup.test.js

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 517872ee-fb9c-405f-98ee-0c961618d882

📥 Commits

Reviewing files that changed from the base of the PR and between 3dbd4f4 and 0a85fbc.

📒 Files selected for processing (3)
  • ghost/core/core/frontend/services/data/entry-lookup.js
  • ghost/core/core/frontend/services/data/match-permalink-params.js
  • ghost/core/test/unit/frontend/services/data/entry-lookup.test.js

Walkthrough

Adds a new matchPermalinkParams(permalinks, targetPath) helper that rewrites hyphen-separated permalink patterns so earlier :param tokens cannot greedily consume hyphens belonging to later tokens. entry-lookup now uses this helper to derive matched params from routerOptions.permalinks instead of calling path-match directly. Unit tests were added to verify correct param extraction and entryLookup flags (isEditURL, isUnknownOption) for date-based and generic hyphen-separated permalinks with hyphenated slugs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main change: fixing hyphen-separated permalink parameter parsing, which matches the core objective described in the changeset.
Description check ✅ Passed Description is directly related to the changeset, explaining the approach taken and referencing the linked issue #28076 that motivated the changes.
Linked Issues check ✅ Passed The changeset implements the primary objective from issue #28076 by constraining hyphen-separated date params during route matching, allowing hyphenated slugs to parse correctly [#28076].
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the permalink parameter parsing issue: modifying entry lookup to use the new matcher, adding comprehensive test coverage, and introducing the new matcher utility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-dated-slug-route-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@9larsons 9larsons force-pushed the codex/fix-dated-slug-route-main branch from 66f6a35 to 36521ad Compare May 26, 2026 13:27
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 26, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 30cccb2

Command Status Duration Result
nx run ghost:test:ci:integration ✅ Succeeded 1m 56s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 7m 37s View ↗
nx run ghost:test:ci:legacy ✅ Succeeded 3m 4s View ↗
nx build @tryghost/signup-form ✅ Succeeded <1s View ↗
nx build @tryghost/activitypub ✅ Succeeded 2s View ↗
nx build @tryghost/sodo-search ✅ Succeeded <1s View ↗
nx build @tryghost/portal ✅ Succeeded <1s View ↗
nx build @tryghost/comments-ui ✅ Succeeded <1s View ↗
Additional runs (7) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2026-05-26 14:54:32 UTC

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
ghost/core/test/unit/frontend/services/data/entry-lookup.test.js (1)

129-150: 💤 Low value

Consider asserting lookup.entry.url for consistency.

For consistency with existing tests (lines 61, 112, 124), consider adding an assertion:

assert.equal(lookup.entry.url, '/reportagem/2026-05-22-meu-cpf-foi-parar-na-totalpass/');

This would strengthen the test by verifying the complete entry shape, not just the slug extraction.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ghost/core/test/unit/frontend/services/data/entry-lookup.test.js` around
lines 129 - 150, Add an assertion to this test to verify the resolved entry's
URL is correct: after the existing assertions in the it block for
data.entryLookup (the dated permalinks case), assert that lookup.entry.url
equals '/reportagem/2026-05-22-meu-cpf-foi-parar-na-totalpass/'; this
complements the slug check on postsReadStub.firstCall.args[0].slug and ensures
the returned entry shape includes the expected url property.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@ghost/core/test/unit/frontend/services/data/entry-lookup.test.js`:
- Around line 129-150: Add an assertion to this test to verify the resolved
entry's URL is correct: after the existing assertions in the it block for
data.entryLookup (the dated permalinks case), assert that lookup.entry.url
equals '/reportagem/2026-05-22-meu-cpf-foi-parar-na-totalpass/'; this
complements the slug check on postsReadStub.firstCall.args[0].slug and ensures
the returned entry shape includes the expected url property.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f77b1c91-fcde-42d1-bc17-b96878acdd92

📥 Commits

Reviewing files that changed from the base of the PR and between c18cf6c and 36521ad.

📒 Files selected for processing (2)
  • ghost/core/core/frontend/services/data/entry-lookup.js
  • ghost/core/test/unit/frontend/services/data/entry-lookup.test.js

@9larsons 9larsons force-pushed the codex/fix-dated-slug-route-main branch from 36521ad to 3dbd4f4 Compare May 26, 2026 13:56
@9larsons 9larsons marked this pull request as draft May 26, 2026 13:58
@9larsons 9larsons changed the title 🐛 Fixed date-based permalinks with hyphenated slugs 🐛 Fixed hyphen-separated permalink params May 26, 2026
@9larsons 9larsons force-pushed the codex/fix-dated-slug-route-main branch from 3dbd4f4 to 855b0b5 Compare May 26, 2026 14:05
fixes #28076

path-to-regexp 1.9.0 changed how adjacent hyphen-separated params are captured through path-match. Constraining Ghost's known date tokens during entry lookup keeps existing dated permalink patterns working without pinning an archived transitive dependency.
@9larsons 9larsons force-pushed the codex/fix-dated-slug-route-main branch from 855b0b5 to 30cccb2 Compare May 26, 2026 14:35
@9larsons 9larsons marked this pull request as ready for review May 26, 2026 14:42
@9larsons 9larsons enabled auto-merge (squash) May 26, 2026 14:42
@9larsons 9larsons merged commit 20c82f1 into main May 26, 2026
47 checks passed
@9larsons 9larsons deleted the codex/fix-dated-slug-route-main branch May 26, 2026 14:58
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.

Dynamic routing regression with {year}-{month}-{day}-{slug} after path-to-regexp 1.9.0

1 participant