Skip to content

fix: relative base URL double-prefix and skipped inline styles - #1826

Merged
cossssmin merged 2 commits into
masterfrom
fix/baseurl-double-prefix-inline-style
Aug 3, 2026
Merged

fix: relative base URL double-prefix and skipped inline styles#1826
cossssmin merged 2 commits into
masterfrom
fix/baseurl-double-prefix-inline-style

Conversation

@cossssmin

@cossssmin cossssmin commented Aug 3, 2026

Copy link
Copy Markdown
Member

Two more relative-base bugs in the base URL transformer, both surfaced with a relative url.base (e.g. /images/) and masked by absolute bases — an absolute base becomes absolute after one prepend, so isAbsoluteUrl self-guards. Follow-up to #1825 (the infinite-loop fix), same file.

1. VML src double-prefixed inside MSO comments

A v:image/v:fill src inside an MSO conditional comment is rewritten by both rewriteVMLs and rewriteMsoComments' generic src= pass. With a relative base neither pass sees the value as absolute, so it's prepended twice:

<v:fill src="hero.jpg"> → src="/images//images/hero.jpg"

Fix: guard the MSO/VML passes with startsWith(url) so an already-prefixed src (from the first pass) is left alone. Absolute bases keep self-guarding via isAbsoluteUrl.

2. Inline style url() skipped when tags is restricted

The inline-style url() rewrite sat inside the tags-filter gate, so tags: ['img'] skipped a background image on any non-listed tag:

<td style="background-image: url(bg.jpg)"> → unchanged

The tags filter is meant to restrict source attributes (src/href/…), not CSS url() rewriting — which is governed by inlineCss (mirroring how <style> tags are handled). Fix: move the inline-style rewrite out of the tag gate.

Tests

Added regression tests (relative base): v:fill/v:image in MSO comments prefixed exactly once (no /images//images/), and inline style url() still rewritten under tags: ['img']. Full suite green (1772), lint clean.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed inline CSS URLs so they are consistently rewritten, including on restricted tags.
    • Prevented duplicate base URLs in VML and MSO comment image sources.
    • Preserved tag filtering for supported source attributes.
    • Improved handling of similar paths, ensuring only the intended base URL is applied.

Two more relative-base bugs in the same transformer (both masked by
absolute bases, which self-guard via isAbsoluteUrl after one prepend):

- VML double-prefix: a v:image/v:fill src inside an MSO comment is
  rewritten by both rewriteVMLs and rewriteMsoComments' generic src pass,
  so a relative base is prepended twice (/images//images/…). Guard the
  MSO/VML passes with startsWith(url) so an already-prefixed src is left
  alone.
- Inline style url() skipped: the inline-style url() rewrite sat behind
  the `tags` filter, so `tags: ['img']` skipped a background image on a
  non-listed tag (e.g. <td>). Move it out of the tag gate — it is
  governed by `inlineCss`, like <style> tag handling.

Add regression tests for both (relative base).
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 79c39796-5382-4d8f-9009-ad8202734242

📥 Commits

Reviewing files that changed from the base of the PR and between 00a9b04 and 18a4f1e.

📒 Files selected for processing (2)
  • src/tests/transformers/base.test.ts
  • src/transformers/base.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/transformers/base.ts
  • src/tests/transformers/base.test.ts

📝 Walkthrough

Walkthrough

The transformer now rewrites inline CSS URLs independently of tag filtering. VML and MSO comment processing avoids duplicate relative base URLs. Regression tests cover restricted tags and v:fill and v:image sources.

Changes

URL rewriting behavior

Layer / File(s) Summary
Inline style and tag filtering
src/transformers/base.ts, src/tests/transformers/base.test.ts
Inline CSS URL rewriting now depends only on inlineCss. Other source attributes still depend on the tags filter.
VML and MSO base URL handling
src/transformers/base.ts, src/tests/transformers/base.test.ts
VML and MSO comment rewrites skip URLs that already contain the configured base. Tests cover v:fill, v:image, and boundary-aware paths such as /images2.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main fixes: duplicate relative base prefixes and skipped inline styles.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 fix/baseurl-double-prefix-inline-style

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/transformers/base.ts`:
- Around line 262-267: Update the URL-prefix checks in the VML rewrite
callbacks, including the v:fill and v:image handling, so a source is skipped
only when it matches the configured base path at a path boundary rather than
merely sharing its string prefix; preserve absolute-URL handling and support
bases without a trailing slash. Add regression coverage for both VML elements
using a base such as /images and sources under /images2, ensuring they are
rewritten.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d76d8e8-0b0a-4214-a932-0e148fb093f1

📥 Commits

Reviewing files that changed from the base of the PR and between 6a4ffd1 and 00a9b04.

📒 Files selected for processing (2)
  • src/tests/transformers/base.test.ts
  • src/transformers/base.ts

Comment thread src/transformers/base.ts Outdated
The `startsWith(url)` skip guard false-matched when the base had no
trailing slash: base `/images` would skip (not rewrite) a source under
`/images2` because it merely shares the string prefix. Require a path
boundary (exact match or a following `/`) via `isUnderBase`, applied to
the v:image/v:fill and MSO-comment passes. Add regression coverage for
both VML elements with base `/images` and sources under `/images2`.
@cossssmin
cossssmin merged commit b9d6a02 into master Aug 3, 2026
6 checks passed
@cossssmin
cossssmin deleted the fix/baseurl-double-prefix-inline-style branch August 3, 2026 15:32
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.

1 participant