mirror of https://github.com/sveltejs/svelte
fix: preserve line feed character references in attribute values (#18691)
Fixes #15555 Pass on whether we're in an attribute to not replace the charcode with the whitespace charcode in that casepull/18712/head
parent
34489c10df
commit
b433f3cd87
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: preserve line feed character references in attribute values
|
||||
@ -0,0 +1 @@
|
||||
<p title="A
B">A
B</p>
|
||||
@ -0,0 +1,53 @@
|
||||
{
|
||||
"html": {
|
||||
"type": "Fragment",
|
||||
"start": 0,
|
||||
"end": 32,
|
||||
"children": [
|
||||
{
|
||||
"type": "Element",
|
||||
"start": 0,
|
||||
"end": 32,
|
||||
"name": "p",
|
||||
"attributes": [
|
||||
{
|
||||
"type": "Attribute",
|
||||
"start": 3,
|
||||
"end": 19,
|
||||
"name": "title",
|
||||
"name_loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 3,
|
||||
"character": 3
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 8,
|
||||
"character": 8
|
||||
}
|
||||
},
|
||||
"value": [
|
||||
{
|
||||
"start": 10,
|
||||
"end": 18,
|
||||
"type": "Text",
|
||||
"raw": "A
B",
|
||||
"data": "A\nB"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"children": [
|
||||
{
|
||||
"type": "Text",
|
||||
"start": 20,
|
||||
"end": 28,
|
||||
"raw": "A
B",
|
||||
"data": "A B"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
const { text } = $props();
|
||||
</script>
|
||||
|
||||
<span id="prop">{text}</span>
|
||||
@ -0,0 +1,15 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
// a line feed entity in an attribute value stays a line feed...
|
||||
assert.equal(target.querySelector('#attr')?.getAttribute('title'), 'A\nB');
|
||||
assert.equal(target.querySelector('#attr-decimal')?.getAttribute('title'), 'A\nB');
|
||||
|
||||
// ...including when the attribute is a prop passed to a component
|
||||
assert.equal(target.querySelector('#prop')?.textContent, 'A\nB');
|
||||
|
||||
// other entities in attribute values still decode
|
||||
assert.equal(target.querySelector('#attr-other-entity')?.getAttribute('title'), '©');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import Component from './Component.svelte';
|
||||
</script>
|
||||
|
||||
<span id="attr" title="A
B"></span>
|
||||
<span id="attr-decimal" title="A B"></span>
|
||||
<span id="attr-other-entity" title="©"></span>
|
||||
|
||||
<Component text="A
B" />
|
||||
Loading…
Reference in new issue