From 2cf7c47522280311649ecd9ab904a8e896e8caf4 Mon Sep 17 00:00:00 2001 From: Martin Tirion Date: Thu, 2 Nov 2023 19:22:22 +0100 Subject: [PATCH] Try to fix the length error --- .../DocLinkChecker/Helpers/MarkdownHelper.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs b/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs index 9dfdd16..9abee37 100644 --- a/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs +++ b/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs @@ -237,12 +237,23 @@ private static (PipeTable table, List errors) start--; } - len = markdown.IndexOf('\r', start) - start; - line = markdown.Substring(start, len); + if (markdown.IndexOf('\r') >= 0) + { + len = markdown.IndexOf('\r', start) - start; + } + else if (markdown.IndexOf('\n') >= 0) + { + len = markdown.IndexOf('\n', start) - start; + } + + if (len > 0) + { + line = markdown.Substring(start, len); + } } catch (Exception ex) { - Console.WriteLine($"PipeTable error {ex.Message}.\nfilepath: {markdownFilePath}\nmarkdown: {markdown.Substring(0, 40)}...\nTable: line={table.Line} col={table.Column} start={table.Span.Start}"); + Console.WriteLine($"PipeTable error\nPATH: {markdownFilePath} MD: {markdown.Substring(0, 10)}... TABLE: line={table.Line} col={table.Column} start={table.Span.Start}\n{ex}"); } int row = 0;