Skip to content
Myr

fix(jsx): escape attribute value for "style" (#2390)

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

authored by Taku Amano · committed by GitHub · parent 8e4293b · Browse files · 3 files+8 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+8 added−4 removed

  • tests:+2 added−2 removed
  • other:+6 added−2 removed

3 files+8 added−4 removed

modified:deno_dist/jsx/base.ts+3 added-1 removed
139 unmodified lines
140 const property = k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`)141 return `${property}:${v[k]}`142 })143 .join(';')144 buffer[0] += ` style="${styles}"`144 buffer[0] += ' style="'145 escapeToBuffer(styles, buffer)146 buffer[0] += '"'147 } else if (typeof v === 'string') {148 buffer[0] += ` ${key}="`149 escapeToBuffer(v, buffer)150 buffer[0] += '"'
188 unmodified lines
modified:src/jsx/base.ts+3 added-1 removed
139 unmodified lines
140 const property = k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`)141 return `${property}:${v[k]}`142 })143 .join(';')144 buffer[0] += ` style="${styles}"`144 buffer[0] += ' style="'145 escapeToBuffer(styles, buffer)146 buffer[0] += '"'147 } else if (typeof v === 'string') {148 buffer[0] += ` ${key}="`149 escapeToBuffer(v, buffer)150 buffer[0] += '"'
188 unmodified lines
modified:src/jsx/index.test.tsx+2 added-2 removed
369 unmodified lines
370 <h1371 style={{372 color: 'red',373 fontSize: 'small',374 fontFamily: 'Menlo, Consolas, DejaVu Sans Mono, monospace',374 fontFamily: 'Menlo, Consolas, "DejaVu Sans Mono", monospace',375 }}376 >377 Hello378 </h1>379 )380 expect(template.toString()).toBe(381 '<h1 style="color:red;font-size:small;font-family:Menlo, Consolas, DejaVu Sans Mono, monospace">Hello</h1>'381 '<h1 style="color:red;font-size:small;font-family:Menlo, Consolas, &quot;DejaVu Sans Mono&quot;, monospace">Hello</h1>'382 )383 })384 it('should not convert the strings', () => {385 const template = <h1 style='color:red;font-size:small'>Hello</h1>
375 unmodified lines