Skip to content

Commit 4aad231

Browse files
authored
Merge pull request #1471 from maizzle/fix-baseurl-mso
fix: skip vml tags when replacing sources inside mso comments
2 parents e06d569 + e1a867f commit 4aad231

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/transformers/baseUrl.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,16 @@ const rewriteVMLs = (html, url) => {
103103
* Handle other sources inside MSO comments
104104
*/
105105

106-
// Make a | pipe-separated list of all the default tags and use it to create a regex
106+
// Make a pipe-separated list of all the default tags and use it to create a regex
107107
const uniqueSourceAttributes = [
108108
...new Set(Object.values(defaultTags).flatMap(Object.keys))
109109
].join('|')
110110

111-
const sourceAttrRegex = new RegExp(`\\b(${uniqueSourceAttributes})="([^"]+)"`, 'g')
111+
/**
112+
* This regex uses a negative lookbehind to avoid matching VML elements
113+
* like <v:image> and <v:fill>, which are already handled above.
114+
*/
115+
const sourceAttrRegex = new RegExp(`(?<!<v:image|fill[^>]*]*)\\b(${uniqueSourceAttributes})="([^"]+)"`, 'g')
112116

113117
// Replace all the source attributes inside MSO comments
114118
html = html.replace(/<!--\[if [^\]]+\]>[\s\S]*?<!\[endif\]-->/g, (msoBlock) => {

test/expected/base-url.html

+2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@
9797
<![endif]-->
9898

9999
<!--[if mso]>
100+
<v:image src="https://example.com/image-2.jpg" xmlns:v="urn:schemas-microsoft-com:vml" style="width:600px;height:400px;" />
100101
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" stroked="f" filled="f" style="mso-width-percent: 1000; position: absolute; top: 256px; left: 128x;">
102+
<v:fill type="tile" src="https://example.com/image.png" color="#7bceeb" />
101103
<v:textbox style="mso-fit-shape-to-text:true;" inset="0,0,0,0">
102104
<video src="https://example.com/video.mp4" poster="https://example.com/example.png"></video>
103105
<div>

test/fixtures/base-url.html

+2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@
9999
<![endif]-->
100100

101101
<!--[if mso]>
102+
<v:image src="image-2.jpg" xmlns:v="urn:schemas-microsoft-com:vml" style="width:600px;height:400px;" />
102103
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" stroked="f" filled="f" style="mso-width-percent: 1000; position: absolute; top: 256px; left: 128x;">
104+
<v:fill type="tile" src="image.png" color="#7bceeb" />
103105
<v:textbox style="mso-fit-shape-to-text:true;" inset="0,0,0,0">
104106
<video src="video.mp4" poster="example.png"></video>
105107
<div>

0 commit comments

Comments
 (0)