From 6edac456584ae52cc91767b8b756b1eae91a0f41 Mon Sep 17 00:00:00 2001 From: Mahdi Zand <80402823+mzand111@users.noreply.github.com> Date: Tue, 10 Dec 2024 18:52:19 +0300 Subject: [PATCH] Update MarkdownHeaderTextSplitter.cs This change prevents errors when the markdown file includes lines that start with # but have no following characters. --- .../Abstractions/src/Text/MarkdownHeaderTextSplitter.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Splitters/Abstractions/src/Text/MarkdownHeaderTextSplitter.cs b/src/Splitters/Abstractions/src/Text/MarkdownHeaderTextSplitter.cs index cf551724..18a4b706 100644 --- a/src/Splitters/Abstractions/src/Text/MarkdownHeaderTextSplitter.cs +++ b/src/Splitters/Abstractions/src/Text/MarkdownHeaderTextSplitter.cs @@ -122,6 +122,8 @@ private bool IsHeader(string line, out int len) len = 0; foreach (var header in _headersToSplitOn) { + if (line.Length <= header.Length + 1) + return false;//Empty lines starting with #s should not be considered as headers. Removing this line would result in exceptions in that conditions if (line.Trim().StartsWith(header, StringComparison.Ordinal) && line[header.Length] == ' ') { len = header.Length; @@ -131,4 +133,4 @@ private bool IsHeader(string line, out int len) return false; } -} \ No newline at end of file +}