Merge pull request #3149 from Conduitry/preprocess-attribute-parsing-fix

preprocess: fix handling of attribute values containing `=`
pull/3151/head
Rich Harris 5 years ago committed by GitHub
commit 0a14009f4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,17 +21,17 @@ interface Processed {
dependencies?: string[];
}
function parse_attribute_value(value: string) {
return /^['"]/.test(value) ?
value.slice(1, -1) :
value;
}
function parse_attributes(str: string) {
const attrs = {};
str.split(/\s+/).filter(Boolean).forEach(attr => {
const [name, value] = attr.split('=');
attrs[name] = value ? parse_attribute_value(value) : true;
const p = attr.indexOf('=');
if (p === -1) {
attrs[attr] = true;
} else {
attrs[attr.slice(0, p)] = `'"`.includes(attr[p + 1]) ?
attr.slice(p + 2, -1) :
attr.slice(p + 1);
}
});
return attrs;
}

@ -0,0 +1,5 @@
export default {
preprocess: {
style: ({ attributes }) => attributes.foo && attributes.foo.includes('=') ? { code: '' } : null
}
};

@ -0,0 +1,3 @@
<style foo="bar=baz">
foo {}
</style>
Loading…
Cancel
Save