Skip to content

Commit 4976fbc

Browse files
authored
Fix sub-path resolution in DiagnosticLinkInlineParser (#884)
* Fix sub-path resolution in DiagnosticLinkInlineParser Ensure sub-prefix calculations handle edge cases where lastIndexOf returns -1. This prevents potential runtime errors and ensures correct path resolution for sibling links. Add `elasticsearch` to our smoke tests since it's a high traffic repository. * Update landing-page-path for elastic/elasticsearch Corrected the landing-page-path to ensure consistent trailing slash usage. This aligns with the paths of other repositories and prevents potential inconsistencies in URL handling. * off by one :sadpanda:
1 parent a1ed5fe commit 4976fbc

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

.github/workflows/smoke-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
include:
1414
- repository: elastic/docs-content
1515
landing-page-path-output: /docs/
16+
- repository: elastic/elasticsearch
17+
landing-page-path-output: /docs/reference/
1618
- repository: elastic/apm-agent-android
1719
landing-page-path-output: /docs/reference/
1820

src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con
309309
// './' current path lookups should be relative to sub-path.
310310
// If it's not e.g /reference/cloud-k8s/api-docs/ these links should resolve on folder up.
311311
var siblingsGoToCurrent = url.StartsWith("./") && markdownPath == "index.md";
312-
if (!siblingsGoToCurrent)
313-
subPrefix = subPrefix[..subPrefix.LastIndexOf('/')];
312+
var lastIndexPath = subPrefix.LastIndexOf('/');
313+
if (lastIndexPath >= 0 && !siblingsGoToCurrent)
314+
subPrefix = subPrefix[..lastIndexPath];
314315

315316
var combined = '/' + Path.Combine(subPrefix, url).TrimStart('/');
316317
url = Path.GetFullPath(combined);

0 commit comments

Comments
 (0)