| 1908 | * @returns {string} The html representation of the highlighted regex | 1908 | * @returns {string} The html representation of the highlighted regex |
| 1909 | */ | 1909 | */ |
| 1910 | export function highlightRegex(regexStr) { | 1910 | export function highlightRegex(regexStr) { |
| 1911 | // Function to escape HTML special characters for safety | 1911 | // Function to escape special characters for safety or readability |
| 1912 | const escapeHtml = (str) => str.replace(/[&<>"']/g, match => ({ | 1912 | const escape = (str) => str.replace(/[&<>"'\x01]/g, match => ({ |
| 1913 | '&': '&', '<': '<', '>': '>', '"': '"', '\'': ''', | 1913 | '&': '&', '<': '<', '>': '>', '"': '"', '\'': ''', '\x01': '\\x01', |
| 1914 | })[match]); | 1914 | })[match]); |
| 1915 | | 1915 | |
| 1916 | // Replace special characters with their HTML-escaped forms | 1916 | // Replace special characters with their escaped forms |
| 1917 | regexStr = escapeHtml(regexStr); | 1917 | regexStr = escape(regexStr); |
| 1918 | | 1918 | |
| 1919 | // Patterns that we want to highlight only if they are not escaped | 1919 | // Patterns that we want to highlight only if they are not escaped |
| 1920 | function getPatterns() { | 1920 | function getPatterns() { |