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 fileTake it
The walk stopped after 200 commits: lines older than 309c38a point at it.
denoifyYusuke Wadabefore adoption309c38a
lines 1–5why, one step back1export 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 back6// https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/server/escapeTextForBrowser.jsdenoifyYusuke Wadabefore adoption309c38a
line 7why, one step back7fix(jsx): escapeToBuffer vulnerability (#1266)Codinakbefore adoption1495f8b
line 8why, one step back8const escapeRe = /[&<>'"]/denoifyYusuke Wadabefore adoption309c38a
lines 9–24why, one step back910export 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 = '"'fix(jsx): escapeToBuffer vulnerability (#1266)Codinakbefore adoption1495f8b
lines 25–27why, one step back25 break26 case 39: // '27 escape = '''denoifyYusuke Wadabefore adoption309c38a
lines 28–47why, one step back28 break29 case 38: // &30 escape = '&'31 break32 case 60: // <33 escape = '<'34 break35 case 62: // >36 escape = '>'37 break38 default:39 continue40 }4142 buffer[0] += str.substring(lastIndex, index) + escape43 lastIndex = index + 144 }4546 buffer[0] += str.substring(lastIndex, index)47}