Merge pull request #2871 from steve02081504/patch-4

fix `\x01` display in modern WI editor
This commit is contained in:
Cohee 2024-09-18 22:09:27 +03:00 committed by GitHub
commit 6d731bbefe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1908,13 +1908,13 @@ export function select2ChoiceClickSubscribe(control, action, { buttonStyle = fal
* @returns {string} The html representation of the highlighted regex * @returns {string} The html representation of the highlighted regex
*/ */
export function highlightRegex(regexStr) { export function highlightRegex(regexStr) {
// Function to escape HTML special characters for safety // Function to escape special characters for safety or readability
const escapeHtml = (str) => str.replace(/[&<>"']/g, match => ({ const escape = (str) => str.replace(/[&<>"'\x01]/g, match => ({
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', '\'': '&#39;', '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', '\'': '&#39;', '\x01': '\\x01',
})[match]); })[match]);
// Replace special characters with their HTML-escaped forms // Replace special characters with their escaped forms
regexStr = escapeHtml(regexStr); regexStr = escape(regexStr);
// Patterns that we want to highlight only if they are not escaped // Patterns that we want to highlight only if they are not escaped
function getPatterns() { function getPatterns() {