Commit 4ea50bc3 by Roy Committed by GitHub

fix: filename with whitespace will cause regex unmatched (#6154)

* fix: filename with whitespace will cause regex unmatched

* chore: add unit tests
parent 5dab0b06
...@@ -53,10 +53,9 @@ export function replaceS3KeyToPreviewUrl(documentQuoteText: string, expiredTime: ...@@ -53,10 +53,9 @@ export function replaceS3KeyToPreviewUrl(documentQuoteText: string, expiredTime:
if (!documentQuoteText || typeof documentQuoteText !== 'string') if (!documentQuoteText || typeof documentQuoteText !== 'string')
return documentQuoteText as string; return documentQuoteText as string;
const prefixPattern = Object.values(S3Sources) const prefixes = Object.values(S3Sources);
.map((pattern) => `${pattern}\\/[^\\s)]+`) const pattern = prefixes.map((p) => `${p}\\/[^)]+`).join('|');
.join('|'); const regex = new RegExp(String.raw`(!?)\[([^\]]*)\]\(\s*(?!https?:\/\/)(${pattern})\s*\)`, 'g');
const regex = new RegExp(String.raw`(!?)\[([^\]]*)\]\((?!https?:\/\/)(${prefixPattern})\)`, 'g');
const matches = Array.from(documentQuoteText.matchAll(regex)); const matches = Array.from(documentQuoteText.matchAll(regex));
let content = documentQuoteText; let content = documentQuoteText;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment