Skip to content

Commit eb3eb98

Browse files
authored
Merge pull request #40 from Ellerbach/doclinkchecker/fix-orphaned-resources-validation
Fix orphaned resources validation.
2 parents 0cc5252 + 1d1474c commit eb3eb98

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DocLinkChecker.Helpers
22
{
33
using System;
4+
using System.Collections;
45
using System.Collections.Generic;
56
using System.Diagnostics;
67
using System.IO;
@@ -220,17 +221,29 @@ private static (PipeTable table, List<MarkdownError> errors)
220221
private static (PipeTable table, List<MarkdownError> errors)
221222
ValidatePipeTableWithText(string markdownFilePath, string markdown, Table table)
222223
{
223-
PipeTable pipeTable = new (markdownFilePath, table.Line, table.Column);
224+
PipeTable pipeTable = null;
225+
int start = 0;
226+
int len = 0;
227+
string line = string.Empty;
224228
List<MarkdownError> errors = new ();
225229

226-
int start = table.Span.Start;
227-
while (start > 0 && markdown.Substring(start, 1) != "\n")
230+
try
228231
{
229-
start--;
230-
}
232+
pipeTable = new (markdownFilePath, table.Line, table.Column);
233+
234+
start = Math.Max(table.Span.Start, 0);
235+
while (start > 0 && markdown.Substring(start, 1) != "\n")
236+
{
237+
start--;
238+
}
231239

232-
int len = markdown.IndexOf('\r', start) - start;
233-
string line = markdown.Substring(start, len);
240+
len = markdown.IndexOf('\r', start) - start;
241+
line = markdown.Substring(start, len);
242+
}
243+
catch (Exception ex)
244+
{
245+
Console.WriteLine($"PipeTable error {ex.Message}.\nfilepath: {markdownFilePath}\nmarkdown: {markdown.Substring(0, 40)}...\nTable: line={table.Line} col={table.Column} start={table.Span.Start}");
246+
}
234247

235248
int row = 0;
236249
int nrCols = -1;

src/DocLinkChecker/DocLinkChecker/Services/ResourceValidatorService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public ResourceValidatorService(
7171
orphanedResources.Add(resourceFullPath);
7272
errors.Add(
7373
new MarkdownError(
74-
_fileService.GetRelativePath(resourceFullPath, _config.DocumentationFiles.SourceFolder),
74+
_fileService.GetRelativePath(_config.DocumentationFiles.SourceFolder, resourceFullPath),
7575
0,
7676
0,
7777
MarkdownErrorSeverity.Error,

0 commit comments

Comments
 (0)