Skip to content
Myr

fix(jsx): Write the raw value if the value is a HtmlEscaped string (#1739)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(jsx): Write the raw value if the value is a HtmlEscaped string * chore: denoify

authored by Taku Amano · committed by GitHub · parent 79dc187 · Browse files · 3 files+12 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+12 added−4 removed

  • tests:+8 added−0 removed
  • other:+4 added−4 removed

3 files+12 added−4 removed

modified:deno_dist/jsx/index.ts+2 added-2 removed
128 unmodified lines
129 } else if (typeof v === 'string') {130 buffer[0] += ` ${key}="`131 escapeToBuffer(v, buffer)132 buffer[0] += '"'133 } else if (typeof v === 'number') {134 buffer[0] += ` ${key}="${v}"`133 } else if (v === null || v === undefined) {134 // Do nothing135 } else if (typeof v === 'number' || (v as HtmlEscaped).isEscaped) {136 buffer[0] += ` ${key}="${v}"`137 } else if (typeof v === 'boolean' && booleanAttributes.includes(key)) {138 if (v) {139 buffer[0] += ` ${key}=""`140 }
149 unmodified lines
modified:src/jsx/index.test.tsx+8 added
363 unmodified lines
364 const template = <h1 style='color:red;font-size:small'>Hello</h1>365 expect(template.toString()).toBe('<h1 style="color:red;font-size:small">Hello</h1>')366 })367 })368369 describe('HtmlEscaped in props', () => {370 it('should not be double-escaped', () => {371 const escapedString = html`${'<html-escaped-string>'}`372 const template = <span data-text={escapedString}>Hello</span>373 expect(template.toString()).toBe('<span data-text="&lt;html-escaped-string&gt;">Hello</span>')374 })375 })376})377378describe('memo', () => {379 it('memoized', () => {
165 unmodified lines
modified:src/jsx/index.ts+2 added-2 removed
128 unmodified lines
129 } else if (typeof v === 'string') {130 buffer[0] += ` ${key}="`131 escapeToBuffer(v, buffer)132 buffer[0] += '"'133 } else if (typeof v === 'number') {134 buffer[0] += ` ${key}="${v}"`133 } else if (v === null || v === undefined) {134 // Do nothing135 } else if (typeof v === 'number' || (v as HtmlEscaped).isEscaped) {136 buffer[0] += ` ${key}="${v}"`137 } else if (typeof v === 'boolean' && booleanAttributes.includes(key)) {138 if (v) {139 buffer[0] += ` ${key}=""`140 }
149 unmodified lines