Skip to content
Myr

html.ts

This file

Path

src/utils/html.ts

47 lines · 1.1 KiB · TypeScript

Last changed by

docs: support change of escapeTextForBrowser path in react (#1336)Sor4chibefore adoption8ab0ccd

History of this file

Take it

The walk stopped after 200 commits: lines older than 86afe03 point at it.

chore: update sponsor link (#931)Yusuke Wadabefore adoption86afe03

lines 1–5why, one step back
1export type HtmlEscaped = { isEscaped: true }
2export type HtmlEscapedString = string & HtmlEscaped3export type StringBuffer = [string]45// The `escapeToBuffer` implementation is based on code from the MIT licensed `react-dom` package.

docs: support change of escapeTextForBrowser path in react (#1336)Sor4chibefore adoption8ab0ccd

line 6why, one step back
6// https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/server/escapeTextForBrowser.js

chore: update sponsor link (#931)Yusuke Wadabefore adoption86afe03

line 7why, one step back
7

fix(jsx): escapeToBuffer vulnerability (#1266)Codinakbefore adoption1495f8b

line 8why, one step back
8const escapeRe = /[&<>'"]/

chore: update sponsor link (#931)Yusuke Wadabefore adoption86afe03

lines 9–24why, one step back
9
10export const escapeToBuffer = (str: string, buffer: StringBuffer): void => {11 const match = str.search(escapeRe)12 if (match === -1) {13 buffer[0] += str14 return15 }1617 let escape18 let index19 let lastIndex = 02021 for (index = match; index < str.length; index++) {22 switch (str.charCodeAt(index)) {23 case 34: // "24 escape = '&quot;'

fix(jsx): escapeToBuffer vulnerability (#1266)Codinakbefore adoption1495f8b

lines 25–27why, one step back
25 break
26 case 39: // '27 escape = '&#39;'

chore: update sponsor link (#931)Yusuke Wadabefore adoption86afe03

lines 28–47why, one step back
28 break
29 case 38: // &30 escape = '&amp;'31 break32 case 60: // <33 escape = '&lt;'34 break35 case 62: // >36 escape = '&gt;'37 break38 default:39 continue40 }4142 buffer[0] += str.substring(lastIndex, index) + escape43 lastIndex = index + 144 }4546 buffer[0] += str.substring(lastIndex, index)47}