Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(chat): scan question reference punctuation in linear time

Lizi5fe9a853d3ed
diff --git a/packages/maker-shared/src/questionReferences.ts b/packages/maker-shared/src/questionReferences.ts
index 4a9263130e..64bfd1a6d0 100644
--- a/packages/maker-shared/src/questionReferences.ts
+++ b/packages/maker-shared/src/questionReferences.ts
@@ -56,7 +56,11 @@ export function splitQuestionReferences(text: string): QuestionReferencePart[] {
append({ text: href, href });
append({ text: raw.slice(href.length) });
} else {
- const href = raw.replace(/[.,;!?]+$/, '');
+ // Scan backwards once: an unanchored suffix regex retries at every
+ // punctuation character when the token ends with ordinary text.
+ let hrefEnd = raw.length;
+ while (hrefEnd > 0 && '.,;!?'.includes(raw[hrefEnd - 1])) hrefEnd--;
+ const href = raw.slice(0, hrefEnd);
const reference = isReference(href);
// An unquoted absolute path may contain spaces. Never turn just its
// trailing fragment into a relative link; code/labelled references can