Skip to content

Commit 395b38c

Browse files
committed
Included style attribute in early exit check
no-issue The early exit optimization was filtering out the style attribute, which meant HTML containing only style attributes with URLs (like background-image: url(...)) would skip parsing entirely and not have their URLs transformed.
1 parent c4adac9 commit 395b38c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/url-utils/src/utils/html-transform.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const cheerio = require('cheerio');
44

55
export const transformAttributes = ['href', 'src', 'srcset', 'style'];
66
export const earlyExitMatchStr = transformAttributes
7-
.filter(attr => attr !== 'style')
87
.map(attr => `${attr}=`)
98
.join('|');
109

packages/url-utils/test/unit/utils/html-relative-to-absolute.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,12 @@ describe('utils: htmlRelativeToAbsolute()', function () {
273273
htmlRelativeToAbsolute('<img srcset="/image-4x.png 4x, /image-2x.png 2x">)', url, itemPath, options);
274274
cheerioLoadSpy.callCount.should.equal(3, 'srcset didn\'t trigger parse');
275275

276+
htmlRelativeToAbsolute('<div style="background-image: url(\'/image.png\')"></div>', url, itemPath, options);
277+
cheerioLoadSpy.callCount.should.equal(4, 'style didn\'t trigger parse');
278+
276279
options.assetsOnly = true;
277280
htmlRelativeToAbsolute('<a href="/my-post/">post</a>', url, itemPath, options);
278-
cheerioLoadSpy.callCount.should.equal(3, 'href triggered parse when no url matches asset path');
281+
cheerioLoadSpy.callCount.should.equal(4, 'href triggered parse when no url matches asset path');
279282
});
280283
});
281284
});

0 commit comments

Comments
 (0)