MaxMelcher / AzureDevOps.WikiPDFExport

Export Azure DevOps Wiki to PDF
MIT License
191 stars 65 forks source link

Value cannot be null. (Parameter 'path1') when rendering attachments #89

Closed phil-w closed 2 years ago

phil-w commented 2 years ago

Both of these render perfectly in AzureDevOps, but the second will crash any attempt to export it to PDF with an error Value cannot be null. (Parameter 'path1') when rendering attachments using a windows-latest pipeline on Azure Dev Ops.

![image.png](/.attachments/image-30a0a101-2c35-474a-bbf4-a355524956a5.png)

![image.png](.attachments/image-30a0a101-2c35-474a-bbf4-a355524956a5.png)

The code throwing up is below. Note that it allows either format URL, but the one without the leading slash crashes. Easy for the wiki user to fix, but easier if you know what it is.

public void CorrectLinksAndImages(MarkdownObject document, FileInfo file, MarkdownFile mf)
        {
            Log("Correcting Links and Images", LogLevel.Information, 2);
            // walk the document node tree and replace relative image links
            // and relative links to markdown pages
...
                    //handle --attachments-path case
                     if (!string.IsNullOrEmpty(this._options.AttachmentsPath) && link.Url.StartsWith("/.attachments") 
                       ||  link.Url.StartsWith(".attachments"))
                     {
                     ...
                            absPath = Path.GetFullPath(Path.Combine(this._options.AttachmentsPath, linkUrl));
MaxMelcher commented 2 years ago

thanks for reporting it - actually the code to handle this case is in there, but the if clause was not correctly combined...

if (
                            !string.IsNullOrEmpty(this._options.AttachmentsPath) && 
                            (link.Url.StartsWith("/.attachments") || link.Url.StartsWith(".attachments"))
   )

will be fixed in the next release and then both formats work.

phil-w commented 2 years ago

I should have spotted that straight off... but then I always parenthesise that stuff ;-) Thanks for a very handy tool, saved me a ton of work. I only had 2 links with the form which caused this, so by default almost everything worked fine.

Other stuff I noted (it may help someone else:

Tested across 269 pages, windows-latest etc.

MaxMelcher commented 2 years ago

Nice - thanks for sharing the feedback :)