diff --git a/web/build/config/proxy.ts b/web/build/config/proxy.ts index 3de0cb64..65a3eb29 100644 --- a/web/build/config/proxy.ts +++ b/web/build/config/proxy.ts @@ -30,7 +30,7 @@ function createProxyItem(item: App.Service.ServiceConfigItem) { proxy[item.proxyPattern] = { changeOrigin: true, rewrite: path => - path.replace(new RegExp(`^${item.proxyPattern}`), item.key?.startsWith('/') ? item.proxyPattern : ''), + path?.replace(new RegExp(`^${item.proxyPattern}`), item.key?.startsWith('/') ? item.proxyPattern : ''), target: item.baseURL }; diff --git a/web/widgets/searchbox/src/DocSearch.jsx b/web/widgets/searchbox/src/DocSearch.jsx index cf422bfc..671b6806 100644 --- a/web/widgets/searchbox/src/DocSearch.jsx +++ b/web/widgets/searchbox/src/DocSearch.jsx @@ -42,7 +42,7 @@ export const DocSearch = (props) => { const currentHotkeys = useMemo(() => { let formatHotKey = settings?.hotkey; if (!isAppleDevice() && formatHotKey?.includes('meta')) { - formatHotKey = formatHotKey.replace('meta', 'ctrl'); + formatHotKey = formatHotKey?.replace('meta', 'ctrl'); } return formatHotKey ? [formatHotKey] : hotKeys; }, [hotKeys, settings?.hotkey]); diff --git a/web/widgets/searchbox/src/utils.ts b/web/widgets/searchbox/src/utils.ts index c21ea159..1f71dd17 100644 --- a/web/widgets/searchbox/src/utils.ts +++ b/web/widgets/searchbox/src/utils.ts @@ -20,7 +20,7 @@ export function renameKeysWithLevels>(object: T, pref return Object.keys(object).reduce((acc, key) => { const result: any = acc; if (key.startsWith(prefix)) { - const newKey = key.replace(prefix, ''); + const newKey = key?.replace(prefix, ''); result[newKey] = object[key]; } else { result[key] = object[key]; @@ -146,8 +146,8 @@ export function getHighlightedValue>(object: T, prope **/ export function replaceHtmlTagsToHighlight(str: string) { return str - .replace(//g, '') - .replace(/<\/em>/g, ''); + ?.replace(//g, '') + ?.replace(/<\/em>/g, ''); } /* diff --git a/web/widgets/ui-search/src/ChatMessage/Markdown.jsx b/web/widgets/ui-search/src/ChatMessage/Markdown.jsx index 2a2d518e..d94587af 100644 --- a/web/widgets/ui-search/src/ChatMessage/Markdown.jsx +++ b/web/widgets/ui-search/src/ChatMessage/Markdown.jsx @@ -187,7 +187,7 @@ const CustomCode = forwardRef((props, ref) => { function escapeBrackets(text) { const pattern = /(```[\s\S]*?```|`.*?`)|\\\[([\s\S]*?[^\\])\\\]|\\\((.*?)\\\)/g; - return text.replace( + return text?.replace( pattern, (match, codeBlock, squareBracket, roundBracket) => { if (codeBlock) { @@ -206,13 +206,13 @@ function escapeBrackets(text) { function tryWrapHtmlCode(text) { // try add wrap html code (fixed: html codeblock include 2 newline) return text - .replace( + ?.replace( /([`]*?)(\w*?)([\n\r]*?)()/g, (match, quoteStart, doctype) => { return !quoteStart ? "\n```html\n" + doctype : match; } ) - .replace( + ?.replace( /(<\/body>)([\r\n\s]*?)(<\/html>)([\n\r]*)([`]*)([\n\r]*?)/g, (match, bodyEnd, space, htmlEnd, quoteEnd) => { return !quoteEnd ? bodyEnd + space + htmlEnd + "\n```\n" : match;