feat: add tests for incomplete Markdown image handling and improve stream flush logic
This commit introduces a new test, `TestFindIncompleteMarkdownImage`, to validate the detection of incomplete Markdown images in various scenarios. Additionally, it enhances the `holdbackCutoff` function to prioritize handling incomplete Markdown images, ensuring that they are correctly managed during stream flush operations. The changes improve the robustness of image processing in the application, addressing potential issues with unclosed image URLs in Markdown content.
This commit is contained in:
+19
-1
@@ -135,6 +135,22 @@ func findIncompleteStorageURL(s string) int {
|
||||
return loc[0]
|
||||
}
|
||||
|
||||
// incompleteMarkdownImageSuffixRe matches a Markdown image whose destination URL
|
||||
// (the parenthesized part) is not yet closed — e.g. "]*$`)
|
||||
|
||||
// findIncompleteMarkdownImage returns the byte offset of an unclosed  int {
|
||||
loc := incompleteMarkdownImageSuffixRe.FindStringIndex(s)
|
||||
if loc == nil {
|
||||
return -1
|
||||
}
|
||||
return loc[0]
|
||||
}
|
||||
|
||||
// incompleteXMLTagRe matches the opening of an <image…>, <kb…>, or <web…> tag
|
||||
// that reaches the end of the string without a closing '>'.
|
||||
var incompleteXMLTagRe = regexp.MustCompile(
|
||||
@@ -155,7 +171,9 @@ func findIncompleteXMLTag(s string) int {
|
||||
// chunk, or len(chunk) if the chunk is safe to flush entirely.
|
||||
func holdbackCutoff(chunk string) int {
|
||||
cutoff := len(chunk)
|
||||
if idx := findIncompleteStorageURL(chunk); idx >= 0 && idx < cutoff {
|
||||
if idx := findIncompleteMarkdownImage(chunk); idx >= 0 && idx < cutoff {
|
||||
cutoff = idx
|
||||
} else if idx := findIncompleteStorageURL(chunk); idx >= 0 && idx < cutoff {
|
||||
cutoff = idx
|
||||
}
|
||||
if idx := findIncompleteXMLTag(chunk); idx >= 0 && idx < cutoff {
|
||||
|
||||
Reference in New Issue
Block a user