Skip to content

Commit 9e07e3f

Browse files
committed
include solidus in attribute values - fixes sveltejs#1772
1 parent c0ba6fb commit 9e07e3f

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

src/parse/index.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ export class Parser {
136136
return this.template.slice(this.index, this.index + str.length) === str;
137137
}
138138

139+
matchRegex(pattern: RegExp) {
140+
const match = pattern.exec(this.template.slice(this.index));
141+
if (!match || match.index !== 0) return null;
142+
143+
return match[0];
144+
}
145+
139146
allowWhitespace() {
140147
while (
141148
this.index < this.template.length &&
@@ -146,12 +153,9 @@ export class Parser {
146153
}
147154

148155
read(pattern: RegExp) {
149-
const match = pattern.exec(this.template.slice(this.index));
150-
if (!match || match.index !== 0) return null;
151-
152-
this.index += match[0].length;
153-
154-
return match[0];
156+
const result = this.matchRegex(pattern);
157+
if (result) this.index += result.length;
158+
return result;
155159
}
156160

157161
readIdentifier() {

src/parse/state/tag.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,14 @@ function readAttribute(parser: Parser, uniqueNames: Set<string>) {
397397
function readAttributeValue(parser: Parser) {
398398
const quoteMark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null;
399399

400-
const regex = quoteMark === `'`
401-
? /'/
402-
: quoteMark === `"` ? /"/ : /[\s"'=<>\/`]/;
403-
404-
const value = readSequence(parser, () =>
405-
regex.test(parser.template[parser.index])
400+
const regex = (
401+
quoteMark === `'` ? /'/ :
402+
quoteMark === `"` ? /"/ :
403+
/(\/>|[\s"'=<>`])/
406404
);
407405

406+
const value = readSequence(parser, () => !!parser.matchRegex(regex));
407+
408408
if (quoteMark) parser.index += 1;
409409
return value;
410410
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href=https://www.google.com>Google</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"html": {
3+
"start": 0,
4+
"end": 41,
5+
"type": "Fragment",
6+
"children": [
7+
{
8+
"start": 0,
9+
"end": 41,
10+
"type": "Element",
11+
"name": "a",
12+
"attributes": [
13+
{
14+
"start": 3,
15+
"end": 30,
16+
"type": "Attribute",
17+
"name": "href",
18+
"value": [
19+
{
20+
"start": 8,
21+
"end": 30,
22+
"type": "Text",
23+
"data": "https://www.google.com"
24+
}
25+
]
26+
}
27+
],
28+
"children": [
29+
{
30+
"start": 31,
31+
"end": 37,
32+
"type": "Text",
33+
"data": "Google"
34+
}
35+
]
36+
}
37+
]
38+
},
39+
"css": null,
40+
"js": null
41+
}

0 commit comments

Comments
 (0)