Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow unquoted slash while attribute value is empty #13429

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
14 changes: 10 additions & 4 deletions packages/svelte/src/compiler/phases/1-parse/state/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { get_attribute_expression, is_expression_attribute } from '../../../util
import { closing_tag_omitted } from '../../../../html-tree-validation.js';
import { list } from '../../../utils/string.js';

const regex_invalid_unquoted_attribute_value = /^(\/>|[\s"'=<>`])/;
const regex_invalid_unquoted_attribute_value_or_self_closing_tag = /^(\/>|[\s"'=<>`])/;
const regex_invalid_unquoted_attribute_value = /^[\s"'=<>`]/;
const regex_closing_textarea_tag = /^<\/textarea(\s[^>]*)?>/i;
const regex_closing_comment = /-->/;
const regex_whitespace_or_slash_or_closing_tag = /(\s|\/|>)/;
Expand Down Expand Up @@ -633,9 +634,14 @@ function read_attribute_value(parser) {
try {
value = read_sequence(
parser,
() => {
/** @param {number} chunk_length */
(chunk_length) => {
// handle common case of quote marks existing outside of regex for performance reasons
if (quote_mark) return parser.match(quote_mark);

if (chunk_length > 0)
return !!parser.match_regex(regex_invalid_unquoted_attribute_value_or_self_closing_tag);

return !!parser.match_regex(regex_invalid_unquoted_attribute_value);
},
'in attribute value'
Expand Down Expand Up @@ -669,7 +675,7 @@ function read_attribute_value(parser) {

/**
* @param {Parser} parser
* @param {() => boolean} done
* @param {(value: number) => boolean} done
* @param {string} location
* @returns {any[]}
*/
Expand Down Expand Up @@ -699,7 +705,7 @@ function read_sequence(parser, done, location) {
while (parser.index < parser.template.length) {
const index = parser.index;

if (done()) {
if (done(current_chunk.raw.length)) {
flush(parser.index);
return chunks;
} else if (parser.eat('{')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<div class=foo></div>
<div class=foo></div>
<a href=/>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": 40,
"children": [
{
"type": "Element",
Expand All @@ -27,6 +27,45 @@
}
],
"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"
}
]
}
]
}
Expand Down
Loading