Fix WordPress import image variant URL rewrites#911
Fix WordPress import image variant URL rewrites#911ascorbic merged 3 commits intoemdash-cms:mainfrom
Conversation
🦋 Changeset detectedLatest commit: aec3804 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
2247601 to
03b12ba
Compare
There was a problem hiding this comment.
Pull request overview
Fixes WordPress import URL rewriting so content that references WordPress-generated image size variants (e.g. hero-1024x695.jpg) is correctly rewritten even when the urlMap only contains the original attachment URL (e.g. hero.jpg).
Changes:
- Extract URL rewrite helpers into a dedicated module and expand matching to handle WordPress
-NNNxNNNsize suffix variants. - Tighten string URL rewriting to avoid prefix rewrites inside longer filenames (e.g.
...jpg.webp) while still matching common punctuation boundaries. - Add focused unit tests covering variant matching, dimension-named originals, longer-filename guards, and prose punctuation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/astro/routes/api/import/wordpress/rewrite-urls.ts | Switches endpoint implementation to use extracted helper functions for URL matching/rewriting. |
| packages/core/src/astro/routes/api/import/wordpress/rewrite-url-helpers.ts | New helper module implementing base URL matching + WordPress size-suffix handling + safer string matching regex. |
| packages/core/tests/unit/import/wordpress-rewrite-urls.test.ts | New unit tests validating matching and rewrite behavior for variants and edge cases. |
| .changeset/wp-import-size-variant-urls.md | Patch changeset documenting the fix for published package(s). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/review |
|
Let me think about one more potential issue: the regex pattern uses Let me also consider: Let me check if there's a potential issue where the regex's terminator causes incorrect matching of CSS-style URLs: In CSS: Markdown image: JSON in srcset: Overall this PR looks well-implemented. The author addressed the Copilot reviewer's two concerns:
Let me also verify no double-counting issue is introduced as a regression. Looking at for (const [baseUrl, newUrl] of baseMap.entries()) {
const regex = buildBaseUrlMatchRegex(baseUrl);
const matches = newValue.match(regex);
if (matches) {
for (const match of matches) {
if (!exactMap[match]) {
newValue = newValue.split(match).join(newUrl);
...
}
}
}
}If Actually wait, I want to double-check one thing: does the new regex's optional Say string is
OK, looks good. One concern I want to flag though: Potential issue: In the regex, the lookahead What about Alright, I don't see critical bugs. The PR is well-structured: the helpers were extracted, tests were added, and adversarial review addressed found edge cases. The Copilot bot's two concerns were both addressed by the author. Let me look one more time at the And the What about What about What about malformed URL strings where the LAST I think this PR is solid. The only minor observation worth a comment is about the unquoted attribute self-closing case Given the thorough adversarial review the author already performed, the comprehensive tests, the addressing of all Copilot feedback, and the focused scope of the change, I think this is good. LGTM! |
What does this PR do?
Fixes WordPress import media URL rewriting for content that references WordPress-generated image size variants such as
hero-1024x695.jpgwhen the media importurlMaponly contains the original attachment URL, e.g.hero.jpg.The matcher now preserves query-only base matching, then additionally checks a WordPress image-size-suffix candidate for media URLs. String rewrites also allow the same optional size suffix while guarding against prefix rewrites inside longer filenames such as
hero-1024x695.jpg.webp.Closes #645
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
Not visual.
Novelty / overlap check:
Local checks:
Additional review: