forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix escaping in ReactDOMInput code (facebook#26630)
JSON.stringify isn't the right thing here. Luckily this doesn't look to have any security impact.
- Loading branch information
1 parent
2fa6323
commit 9ee7964
Showing
3 changed files
with
34 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/react-dom-bindings/src/client/escapeSelectorAttributeValueInsideDoubleQuotes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* 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) + ' ', | ||
); | ||
} |