Skip to content

Commit 0394de0

Browse files
authored
Merge pull request #110 from Ellerbach/mtirion/fix-issue-109
Fixed problem with non existing link
2 parents fcbaeb6 + 39948ff commit 0394de0

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/DocAssembler/DocAssembler.Test/IssueTests.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace DocAssembler.Test;
1414

1515
public class IssueTests
1616
{
17-
private Faker _faker = new();
1817
private MockFileService _fileService = new();
1918
private MockLogger _mockLogger = new();
2019
private ILogger _logger;
@@ -31,6 +30,45 @@ public IssueTests()
3130
_outputFolder = Path.Combine(_fileService.Root, "out");
3231
}
3332

33+
[Fact]
34+
public async void Issue_90_invalidLinkCausesStartIndexError()
35+
{
36+
_fileService.Files.Clear();
37+
38+
string expected =
39+
@"#Documentation Readme
40+
41+
LINK [title](../../../non-existing-file.md)".NormalizeContent();
42+
43+
var folder = _fileService.AddFolder($"docs");
44+
_fileService.AddFile(folder, "README.md", string.Empty
45+
.AddRaw(expected));
46+
47+
// arrange
48+
AssembleConfiguration config = new AssembleConfiguration
49+
{
50+
DestinationFolder = "out",
51+
ExternalFilePrefix = "https://some-url.com",
52+
Content =
53+
[
54+
new Content
55+
{
56+
SourceFolder = "docs",
57+
DestinationFolder = "general",
58+
Files = { "**" },
59+
}
60+
]
61+
};
62+
63+
InventoryAction action = new(_workingFolder, config, _fileService, _logger);
64+
65+
// act
66+
var ret = await action.RunAsync();
67+
68+
// assert
69+
ret.Should().Be(ReturnCode.Error);
70+
}
71+
3472
[Fact]
3573
public async void Issue_89_refHeaderInSameFile()
3674
{

src/DocAssembler/DocAssembler/Actions/InventoryAction.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ private ReturnCode UpdateLinks()
128128
else
129129
{
130130
var prefix = file.ContentSet!.ExternalFilePrefix ?? _config.ExternalFilePrefix;
131-
if (string.IsNullOrEmpty(prefix))
131+
if (string.IsNullOrEmpty(prefix) ||
132+
!link.UrlFullPath.StartsWith(_workingFolder.NormalizePath(), StringComparison.OrdinalIgnoreCase))
132133
{
133134
// ERROR: no solution to fix this reference
134-
_logger.LogCritical($"Error in a file reference. Link '{link.OriginalUrl}' in '{file.SourcePath}' cannot be resolved and no external file prefix was given.");
135+
_logger.LogCritical($"Error in a file reference in '{file.SourcePath}'. Link '{link.OriginalUrl}' on {link.Line},{link.Column} cannot be resolved or no external file prefix was given.");
135136
ret = ReturnCode.Error;
136137
}
137138
else

0 commit comments

Comments
 (0)