From cb6e353bce181860eb302519516db0cfcb0d2deb Mon Sep 17 00:00:00 2001 From: Millicent Achieng Date: Fri, 13 Oct 2023 21:08:59 +0300 Subject: [PATCH] Remove cross repo links before processing markdown file (#233) --- ApiDoctor.Validation/Tags/TagProcessor.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ApiDoctor.Validation/Tags/TagProcessor.cs b/ApiDoctor.Validation/Tags/TagProcessor.cs index e0ff0c39..39da3dc5 100644 --- a/ApiDoctor.Validation/Tags/TagProcessor.cs +++ b/ApiDoctor.Validation/Tags/TagProcessor.cs @@ -43,7 +43,7 @@ public class TagProcessor private static Regex ValidTagFormat = new Regex(@"^\[TAGS=[-\.\w]+(?:,\s?[-\.\w]*)*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static Regex GetTagList = new Regex(@"\[TAGS=([-\.,\s\w]+)\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); - private static Regex IncludeFormat = new Regex(@"\[!INCLUDE\s*\[[-/.\w]+\]\(([-/.\w]+)\)\s*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static Regex IncludeFormat = new Regex(@"\[!INCLUDE\s*\[[-/.\w~]+\]\(([-/.\w~]+)\)\s*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static Regex AlertFormat = new Regex(@"\[(!NOTE|!TIP|!IMPORTANT|!CAUTION|!WARNING)\s*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static Regex DivFormat = new Regex(@"\[(!div (([\w]*=""[\w]*"")\s*)*)\s*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static Regex VideoFormat = new Regex(@"\[!VIDEO ((https]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -166,6 +166,13 @@ public string Preprocess(FileInfo sourceFile, IssueLogger issues) // Import include file content if (IsIncludeLine(nextLine)) { + // if contains tilde, then file is not in current docset and cannot be validated + if (nextLine.Contains("~")) + { + LogMessage(new ValidationError(ValidationErrorCode.MarkdownParserError, nextLine, "Cannot validate INCLUDE links referencing content outside of doc set")); + continue; + } + var includeFile = GetIncludeFile(nextLine, sourceFile); if (!includeFile.Exists) {