Skip to content

Commit 0a14009

Browse files
authored
Merge pull request #3149 from Conduitry/preprocess-attribute-parsing-fix
preprocess: fix handling of attribute values containing `=`
2 parents 80bf0fd + f78362d commit 0a14009

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/compiler/preprocess/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ interface Processed {
2121
dependencies?: string[];
2222
}
2323

24-
function parse_attribute_value(value: string) {
25-
return /^['"]/.test(value) ?
26-
value.slice(1, -1) :
27-
value;
28-
}
29-
3024
function parse_attributes(str: string) {
3125
const attrs = {};
3226
str.split(/\s+/).filter(Boolean).forEach(attr => {
33-
const [name, value] = attr.split('=');
34-
attrs[name] = value ? parse_attribute_value(value) : true;
27+
const p = attr.indexOf('=');
28+
if (p === -1) {
29+
attrs[attr] = true;
30+
} else {
31+
attrs[attr.slice(0, p)] = `'"`.includes(attr[p + 1]) ?
32+
attr.slice(p + 2, -1) :
33+
attr.slice(p + 1);
34+
}
3535
});
3636
return attrs;
3737
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
preprocess: {
3+
style: ({ attributes }) => attributes.foo && attributes.foo.includes('=') ? { code: '' } : null
4+
}
5+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<style foo="bar=baz">
2+
foo {}
3+
</style>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<style foo="bar=baz"></style>

0 commit comments

Comments
 (0)