MCPcopy Index your code
hub / github.com/FlowiseAI/Flowise / removeInvalidImageMarkdown

Function removeInvalidImageMarkdown

packages/components/src/utils.ts:1284–1311  ·  view source on GitHub ↗
(output: string)

Source from the content-addressed store, hash-verified

1282// Uses indexOf instead of a global regex to avoid O(n²) backtracking when the
1283// input contains many '![' sequences (polynomial ReDoS with the g flag).
1284export const removeInvalidImageMarkdown = (output: string): string => {
1285 if (typeof output !== 'string') return output
1286 let result = ''
1287 let pos = 0
1288 while (pos < output.length) {
1289 const start = output.indexOf('![', pos)
1290 if (start === -1) {
1291 result += output.slice(pos)
1292 break
1293 }
1294 result += output.slice(pos, start)
1295 const closeBracket = output.indexOf(']', start + 2)
1296 if (closeBracket === -1 || output[closeBracket + 1] !== '(') {
1297 result += '!['
1298 pos = start + 2
1299 continue
1300 }
1301 const closeParen = output.indexOf(')', closeBracket + 2)
1302 if (closeParen === -1) {
1303 result += output.slice(start)
1304 break
1305 }
1306 const url = output.slice(closeBracket + 2, closeParen)
1307 if (/^https?:\/\//.test(url)) result += output.slice(start, closeParen + 1)
1308 pos = closeParen + 1
1309 }
1310 return result
1311}
1312
1313/**
1314 * Extract output from array

Callers 3

agentNodeFunction · 0.90
runMethod · 0.90
utils.test.tsFile · 0.90

Calls 1

testMethod · 0.80

Tested by

no test coverage detected