mirror of https://github.com/sveltejs/svelte
parent
32ee6c1bc2
commit
a9b26c3ffe
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: throw runtime error when template returns different html
|
@ -1,6 +1,29 @@
|
||||
/** @param {string} html */
|
||||
export function create_fragment_from_html(html) {
|
||||
import { DEV } from 'esm-env';
|
||||
import * as e from '../errors.js';
|
||||
|
||||
/**
|
||||
* @param {string} html
|
||||
* @param {boolean} [check_structure]
|
||||
*/
|
||||
export function create_fragment_from_html(html, check_structure = true) {
|
||||
var elem = document.createElement('template');
|
||||
elem.innerHTML = html;
|
||||
if (DEV && check_structure) {
|
||||
let replace_comments = html.replaceAll('<!>', '<!---->');
|
||||
let remove_attributes_and_text_input = replace_comments
|
||||
// we remove every attribute since the template automatically adds ="" after boolean attributes
|
||||
.replace(/<([a-z0-9]+)(\s+[^>]+?)?>/g, '<$1>')
|
||||
// we remove the text within the elements because the template change & to & (and similar)
|
||||
.replace(/>([^<>]*)/g, '>');
|
||||
let remove_attributes_and_text_output = elem.innerHTML
|
||||
// we remove every attribute since the template automatically adds ="" after boolean attributes
|
||||
.replace(/<([a-z0-9]+)(\s+[^>]+?)?>/g, '<$1>')
|
||||
// we remove the text within the elements because the template change & to & (and similar)
|
||||
.replace(/>([^<>]*)/g, '>');
|
||||
if (remove_attributes_and_text_input !== remove_attributes_and_text_output) {
|
||||
e.invalid_html_structure(remove_attributes_and_text_input, remove_attributes_and_text_output);
|
||||
}
|
||||
}
|
||||
|
||||
return elem.content;
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client', 'hydrate'],
|
||||
recover: true,
|
||||
runtime_error: 'invalid_html_structure'
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
<svelte:options runes />
|
||||
<p></p>
|
||||
<tr></tr>
|
Loading…
Reference in new issue