Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-boxes-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

Allow unquoted slash in attributes
20 changes: 18 additions & 2 deletions packages/svelte/src/compiler/phases/1-parse/state/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,24 @@ function read_attribute(parser) {
let value = true;
if (parser.eat('=')) {
parser.allow_whitespace();
value = read_attribute_value(parser);
end = parser.index;

if (parser.template[parser.index] === '/' && parser.template[parser.index + 1] === '>') {
const char_start = parser.index;
parser.index++; // consume '/'
value = [
{
start: char_start,
end: char_start + 1,
type: 'Text',
raw: '/',
data: '/'
}
];
end = parser.index;
} else {
value = read_attribute_value(parser);
end = parser.index;
}
} else if (parser.match_regex(regex_starts_with_quote_characters)) {
e.expected_token(parser.index, '=');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<div class=foo></div>
<div class=foo></div>
<a href=/>home</a>
<a href=/foo>home</a>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"html": {
"type": "Fragment",
"start": 0,
"end": 21,
"end": 62,
"children": [
{
"type": "Element",
Expand All @@ -27,6 +27,84 @@
}
],
"children": []
},
{
"type": "Text",
"start": 21,
"end": 22,
"raw": "\n",
"data": "\n"
},
{
"type": "Element",
"start": 22,
"end": 40,
"name": "a",
"attributes": [
{
"type": "Attribute",
"start": 25,
"end": 31,
"name": "href",
"value": [
{
"start": 30,
"end": 31,
"type": "Text",
"raw": "/",
"data": "/"
}
]
}
],
"children": [
{
"type": "Text",
"start": 32,
"end": 36,
"raw": "home",
"data": "home"
}
]
},
{
"type": "Text",
"start": 40,
"end": 41,
"raw": "\n",
"data": "\n"
},
{
"type": "Element",
"start": 41,
"end": 62,
"name": "a",
"attributes": [
{
"type": "Attribute",
"start": 44,
"end": 53,
"name": "href",
"value": [
{
"start": 49,
"end": 53,
"type": "Text",
"raw": "/foo",
"data": "/foo"
}
]
}
],
"children": [
{
"type": "Text",
"start": 54,
"end": 58,
"raw": "home",
"data": "home"
}
]
}
]
}
Expand Down
Loading