Skip to content

Commit 1c1bb33

Browse files
committed
fix(parser): add validation for link tokens to prevent malformed links
1 parent 3b8eb0a commit 1c1bb33

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

packages/markdown-parser/src/parser/inline-parsers/index.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -275,27 +275,30 @@ export function parseInlineTokens(tokens: MarkdownToken[], raw?: string, pPreTok
275275
const textNodeContent = content.slice(0, linkStart)
276276
const linkEnd = content.indexOf('](', linkStart)
277277
if (linkEnd !== -1) {
278-
result.push({
279-
type: 'text',
280-
content: textNodeContent,
281-
raw: textNodeContent,
282-
})
283278
const text = content.slice(linkStart + 1, linkEnd)
284-
result.push({
285-
type: 'link',
286-
href: '',
287-
text,
288-
children: [
289-
{
290-
type: 'text',
291-
content: text,
292-
raw: text,
293-
},
294-
],
295-
loading: true,
296-
} as any)
297-
i++
298-
break
279+
// 过滤一些奇怪的情况
280+
if (!/[[\]()]/.test(text)) {
281+
result.push({
282+
type: 'text',
283+
content: textNodeContent,
284+
raw: textNodeContent,
285+
})
286+
result.push({
287+
type: 'link',
288+
href: '',
289+
text,
290+
children: [
291+
{
292+
type: 'text',
293+
content: text,
294+
raw: text,
295+
},
296+
],
297+
loading: true,
298+
} as any)
299+
i++
300+
break
301+
}
299302
}
300303
}
301304
const preToken = tokens[i - 1]

tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
"baseUrl": ".",
77
"module": "ESNext",
88
"moduleResolution": "Node",
9+
"allowSyntheticDefaultImports": true,
10+
"esModuleInterop": true,
911
"paths": {
10-
"@/*": ["src/*"]
12+
"@/*": ["src/*"],
13+
// Ensure TypeScript can resolve the local workspace package without a build step in CI
14+
"stream-markdown-parser": ["packages/markdown-parser/src/index.ts"],
15+
"stream-markdown-parser/*": ["packages/markdown-parser/src/*"]
1116
},
1217
"resolveJsonModule": true,
1318
"types": ["vite/client", "vue"],

0 commit comments

Comments
 (0)