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: don't escape value attribute #7369

Merged
merged 1 commit into from
Feb 24, 2025
Merged
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
5 changes: 5 additions & 0 deletions .changeset/afraid-garlics-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik.dev/core': patch
---

fix: don't escape value attribute
3 changes: 1 addition & 2 deletions packages/qwik/src/core/client/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ import { qwikDebugToString } from '../debug';
import { assertDefined, assertEqual, assertFalse, assertTrue } from '../shared/error/assert';
import { QError, qError } from '../shared/error/error';
import { DEBUG_TYPE, QContainerValue, VirtualType, VirtualTypeName } from '../shared/types';
import { escapeHTML } from '../shared/utils/character-escaping';
import { isText } from '../shared/utils/element';
import {
ELEMENT_ID,
Expand Down Expand Up @@ -912,7 +911,7 @@ export const vnode_applyJournal = (journal: VNodeJournal) => {
if (isBooleanAttr(element, key)) {
(element as any)[key] = parseBoolean(value);
} else if (key === 'value' && key in element) {
(element as any).value = escapeHTML(String(value));
(element as any).value = String(value);
} else if (key === dangerouslySetInnerHTML) {
(element as any).innerHTML = value!;
} else {
Expand Down
48 changes: 48 additions & 0 deletions packages/qwik/src/core/tests/component.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,54 @@ describe.each([
}
});

it('should not escape input value', async () => {
const Cmp = component$(() => {
const test = useSignal<string>();

return (
<div>
<input
type="text"
value={test.value}
onInput$={$((_, element) => {
test.value = element.value;
})}
/>

<p>{test.value}</p>
</div>
);
});

const { vNode, document } = await render(<Cmp />, { debug });
expect(vNode).toMatchVDOM(
<Component ssr-required>
<div>
<input type="text" />
<p>
<Signal ssr-required></Signal>
</p>
</div>
</Component>
);

// simulate input
const input = document.querySelector('input')!;
input.value = "'";
await trigger(document.body, input, 'input');

expect(vNode).toMatchVDOM(
<Component ssr-required>
<div>
<input type="text" value="'" />
<p>
<Signal ssr-required>'</Signal>
</p>
</div>
</Component>
);
});

it('should render correctly text node in the middle', async () => {
const Cmp = component$(() => {
const signal = useSignal<number>(0);
Expand Down