/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-dom-bindings/src/client/escapeSelectorAttributeValueInsideDoubleQuotes.js
23 строки
855 B
Sophie Alpert
Fix escaping in ReactDOMInput code (#26630)
24 апр 2023, 20:33
Не верифицирован
24 апр 2023, 20:33
9ee7964
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ // When passing user input into querySelector(All) the embedded string must not alter // the semantics of the query. This escape function is safe to use when we know the // provided value is going to be wrapped in double quotes as part of an attribute selector // Do not use it anywhere else // we escape double quotes and backslashes const escapeSelectorAttributeValueInsideDoubleQuotesRegex = /[\n\"\\]/g; export default function escapeSelectorAttributeValueInsideDoubleQuotes( value: string, ): string { return value.replace( escapeSelectorAttributeValueInsideDoubleQuotesRegex, ch => '\\' + ch.charCodeAt(0).toString(16) + ' ', ); }