include solidus in attribute values - fixes #1772

pull/1776/head
Rich Harris 6 years ago
parent c0ba6fb4ef
commit 9e07e3f77f

@ -136,6 +136,13 @@ export class Parser {
return this.template.slice(this.index, this.index + str.length) === str;
}
matchRegex(pattern: RegExp) {
const match = pattern.exec(this.template.slice(this.index));
if (!match || match.index !== 0) return null;
return match[0];
}
allowWhitespace() {
while (
this.index < this.template.length &&
@ -146,12 +153,9 @@ export class Parser {
}
read(pattern: RegExp) {
const match = pattern.exec(this.template.slice(this.index));
if (!match || match.index !== 0) return null;
this.index += match[0].length;
return match[0];
const result = this.matchRegex(pattern);
if (result) this.index += result.length;
return result;
}
readIdentifier() {

@ -397,14 +397,14 @@ function readAttribute(parser: Parser, uniqueNames: Set<string>) {
function readAttributeValue(parser: Parser) {
const quoteMark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null;
const regex = quoteMark === `'`
? /'/
: quoteMark === `"` ? /"/ : /[\s"'=<>\/`]/;
const value = readSequence(parser, () =>
regex.test(parser.template[parser.index])
const regex = (
quoteMark === `'` ? /'/ :
quoteMark === `"` ? /"/ :
/(\/>|[\s"'=<>`])/
);
const value = readSequence(parser, () => !!parser.matchRegex(regex));
if (quoteMark) parser.index += 1;
return value;
}

@ -0,0 +1 @@
<a href=https://www.google.com>Google</a>

@ -0,0 +1,41 @@
{
"html": {
"start": 0,
"end": 41,
"type": "Fragment",
"children": [
{
"start": 0,
"end": 41,
"type": "Element",
"name": "a",
"attributes": [
{
"start": 3,
"end": 30,
"type": "Attribute",
"name": "href",
"value": [
{
"start": 8,
"end": 30,
"type": "Text",
"data": "https://www.google.com"
}
]
}
],
"children": [
{
"start": 31,
"end": 37,
"type": "Text",
"data": "Google"
}
]
}
]
},
"css": null,
"js": null
}
Loading…
Cancel
Save