diff --git a/web/app/components/app/configuration/index.tsx b/web/app/components/app/configuration/index.tsx index 091900642a..b3b31ab6b3 100644 --- a/web/app/components/app/configuration/index.tsx +++ b/web/app/components/app/configuration/index.tsx @@ -108,7 +108,8 @@ const Configuration: FC = () => { const [hasFetchedDetail, setHasFetchedDetail] = useState(false) const isLoading = !hasFetchedDetail const pathname = usePathname() - const matched = pathname.match(/\/app\/([^/]+)/) + const appIdRegex = /\/app\/([^/]+)/ + const matched = appIdRegex.exec(pathname) const appId = (matched?.length && matched[1]) ? matched[1] : '' const [mode, setMode] = useState('') const [publishedConfig, setPublishedConfig] = useState(null) diff --git a/web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx b/web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx index 34ecf23c80..e3dde131f2 100644 --- a/web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx +++ b/web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx @@ -26,7 +26,8 @@ const AnnotationReply = ({ const { t } = useTranslation() const router = useRouter() const pathname = usePathname() - const matched = pathname.match(/\/app\/([^/]+)/) + const appIdRegex = /\/app\/([^/]+)/ + const matched = appIdRegex.exec(pathname) const appId = (matched?.length && matched[1]) ? matched[1] : '' const featuresStore = useFeaturesStore() const annotationReply = useFeatures(s => s.features.annotationReply) diff --git a/web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx b/web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx index 6e93c0c871..bf84e1959c 100644 --- a/web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx +++ b/web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx @@ -28,7 +28,8 @@ const VoiceParamConfig = ({ }: VoiceParamConfigProps) => { const { t } = useTranslation() const pathname = usePathname() - const matched = pathname.match(/\/app\/([^/]+)/) + const appIdRegex = /\/app\/([^/]+)/ + const matched = appIdRegex.exec(pathname) const appId = (matched?.length && matched[1]) ? matched[1] : '' const text2speech = useFeatures(state => state.features.text2speech) const featuresStore = useFeaturesStore() diff --git a/web/app/components/base/markdown/markdown-utils.ts b/web/app/components/base/markdown/markdown-utils.ts index 0089bef0ac..b53d9bc1f1 100644 --- a/web/app/components/base/markdown/markdown-utils.ts +++ b/web/app/components/base/markdown/markdown-utils.ts @@ -11,7 +11,10 @@ export const preprocessLaTeX = (content: string) => { return content const codeBlockRegex = /```[\s\S]*?```/g - const codeBlocks = content.match(codeBlockRegex) || [] + const codeBlocks: string[] = [] + let match + while ((match = codeBlockRegex.exec(content)) !== null) + codeBlocks.push(match[0]) const escapeReplacement = (str: string) => str.replace(/\$/g, '_TMP_REPLACE_DOLLAR_') let processedContent = content.replace(codeBlockRegex, 'CODE_BLOCK_PLACEHOLDER') diff --git a/web/app/components/base/mermaid/index.tsx b/web/app/components/base/mermaid/index.tsx index c1deab6e09..d35a6ce2b5 100644 --- a/web/app/components/base/mermaid/index.tsx +++ b/web/app/components/base/mermaid/index.tsx @@ -236,7 +236,8 @@ const Flowchart = (props: FlowchartProps) => { .split('\n') .map((line) => { // Gantt charts have specific syntax needs. - const taskMatch = line.match(/^\s*([^:]+?)\s*:\s*(.*)/) + const taskRegex = /^\s*([^:]+?)\s*:\s*(.*)/ + const taskMatch = taskRegex.exec(line) if (!taskMatch) return line // Not a task line, return as is. @@ -245,7 +246,12 @@ const Flowchart = (props: FlowchartProps) => { // Rule 1: Correct multiple "after" dependencies ONLY if they exist. // This is a common mistake, e.g., "..., after task1, after task2, ..." - const afterCount = (paramsStr.match(/after /g) || []).length + const afterMatches: string[] = [] + const afterRegex = /after /g + let afterMatch + while ((afterMatch = afterRegex.exec(paramsStr)) !== null) + afterMatches.push(afterMatch[0]) + const afterCount = afterMatches.length if (afterCount > 1) paramsStr = paramsStr.replace(/,\s*after\s+/g, ' ') diff --git a/web/app/components/base/mermaid/utils.ts b/web/app/components/base/mermaid/utils.ts index 9d56494227..cd2d73ebbf 100644 --- a/web/app/components/base/mermaid/utils.ts +++ b/web/app/components/base/mermaid/utils.ts @@ -167,10 +167,11 @@ export function isMermaidCodeComplete(code: string): boolean { const isBalanced = true // Check for common syntax errors + const arrowRegex = /\S+\s*-->\s*\S+/ const hasNoSyntaxErrors = !trimmedCode.includes('undefined') && !trimmedCode.includes('[object Object]') && trimmedCode.split('\n').every(line => - !(line.includes('-->') && !line.match(/\S+\s*-->\s*\S+/))) + !(line.includes('-->') && !arrowRegex.test(line))) return hasValidStart && isBalanced && hasNoSyntaxErrors } diff --git a/web/app/components/plugins/install-plugin/utils.ts b/web/app/components/plugins/install-plugin/utils.ts index f19a7fd287..a97420345f 100644 --- a/web/app/components/plugins/install-plugin/utils.ts +++ b/web/app/components/plugins/install-plugin/utils.ts @@ -53,7 +53,8 @@ export const pluginManifestInMarketToPluginProps = (pluginManifest: PluginManife } export const parseGitHubUrl = (url: string): GitHubUrlInfo => { - const match = url.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/?$/) + const regex = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/?$/ + const match = regex.exec(url) return match ? { isValid: true, owner: match[1], repo: match[2] } : { isValid: false } } diff --git a/web/app/components/tools/mcp/modal.tsx b/web/app/components/tools/mcp/modal.tsx index 211d594caf..e4f0d530d8 100644 --- a/web/app/components/tools/mcp/modal.tsx +++ b/web/app/components/tools/mcp/modal.tsx @@ -37,7 +37,8 @@ export type DuplicateAppModalProps = { const DEFAULT_ICON = { type: 'emoji', icon: '🧿', background: '#EFF1F5' } const extractFileId = (url: string) => { - const match = url.match(/files\/(.+?)\/file-preview/) + const regex = /files\/(.+?)\/file-preview/ + const match = regex.exec(url) return match ? match[1] : null } const getIcon = (data?: ToolWithProvider) => { diff --git a/web/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars.tsx b/web/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars.tsx index abc7d8dbc4..9e938051a1 100644 --- a/web/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars.tsx +++ b/web/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars.tsx @@ -84,7 +84,8 @@ const CodeEditor: FC = ({ const getUniqVarName = (varName: string) => { if (varList.find(v => v.variable === varName)) { - const match = varName.match(/_(\d+)$/) + const regex = /_(\d+)$/ + const match = regex.exec(varName) const index = (() => { if (match) diff --git a/web/app/components/workflow/nodes/_base/components/support-var-input/index.tsx b/web/app/components/workflow/nodes/_base/components/support-var-input/index.tsx index 3be1262e14..47d80c109f 100644 --- a/web/app/components/workflow/nodes/_base/components/support-var-input/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/support-var-input/index.tsx @@ -25,7 +25,8 @@ const SupportVarInput: FC = ({ const renderSafeContent = (inputValue: string) => { const parts = inputValue.split(/(\{\{[^}]+\}\}|\n)/g) return parts.map((part, index) => { - const variableMatch = part.match(/^\{\{([^}]+)\}\}$/) + const variableRegex = /^\{\{([^}]+)\}\}$/ + const variableMatch = variableRegex.exec(part) if (variableMatch) { return ( { [CodeLanguage.python3]: /def\s+main\s*\((.*?)\)/, [CodeLanguage.javascript]: /function\s+main\s*\((.*?)\)/, } - const match = code.match(patterns[language]) + const match = patterns[language].exec(code) const params: string[] = [] if (match?.[1]) { diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx index a93155113e..114a7d5580 100644 --- a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx +++ b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/condition-item.tsx @@ -84,7 +84,7 @@ const ConditionItem = ({ ) { const regex = isCommonVariable ? COMMON_VARIABLE_REGEX : VARIABLE_REGEX const matchedStartNumber = isCommonVariable ? 2 : 3 - const matched = condition.value.match(regex) + const matched = regex.exec(condition.value) if (matched?.length) { return {