Skip to content

Commit fb144be

Browse files
Bart Venemanbartveneman
authored andcommitted
fix wrong embed type reporting
1 parent 38b580d commit fb144be

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/stylesheet/stylesheet.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
export function getEmbedType(embed) {
1+
export function getEmbedType(/** @type string */embed) {
22
// data:image/gif;base64,R0lG
3-
var start = 5 // `data:`.length
4-
var semicolon = embed.indexOf(';')
3+
let start = 5 // `data:`.length
4+
let semicolon = embed.indexOf(';')
5+
let comma = embed.indexOf(',')
56

67
if (semicolon === -1) {
7-
var comma = embed.indexOf(',')
88
return embed.substring(start, comma)
99
}
1010

11+
if (comma !== -1 && comma < semicolon) {
12+
return embed.substring(start, comma);
13+
}
14+
1115
return embed.substring(start, semicolon)
1216
}

src/stylesheet/stylesheet.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ Stylesheet('correctly extracts embed types', () => {
188188
['application/font-woff', 'data:application/font-woff;base64,d09GRgAB'],
189189
['font/opentype', 'data:font/opentype;base64,T1RUTwAJAIAAAw'],
190190
['image/png', 'data:image/png;base64,iVBORw0KGgoAAAANS'],
191+
['image/svg+xml', `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28.84 26.6'%3E%3Cdefs%3E%3Cstyle%3E.cls-1%7Bfill:%23e93e32;%7D%3C/style%3E%3C/defs%3E%3Ctitle%3EArtboard 29%3C/title%3E%3Cpath class='cls-1' d='M3.29,2.73a66.7,66.7,0,0,0,3.21,9.52l6.29,1.08L8.1,15.53c2.91,5.28,7,9.09,12.14,4.55L25,24.52l.57-.52-3.83-5.48c3.6-4.32,1.74-7.76-1.93-10.36L17,13.29l-.1-6.85A43.83,43.83,0,0,0,11,4L9,7.7,9,3.39c-2.2-.65-4.07-1.08-5.08-1.3A.52.52,0,0,0,3.29,2.73Z'/%3E%3C/svg%3E`]
191192
].forEach(([expected, fixture]) => {
192193
assert.is(getEmbedType(fixture), expected)
193194
})

0 commit comments

Comments
 (0)