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

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