From fb1fdf76846266d29b3504999c832f2c0cb46449 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 7 Jul 2025 23:56:00 +0200 Subject: [PATCH 1/2] Fix RoleParser --- src/Elastic.Markdown/Myst/Roles/RoleParser.cs | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Roles/RoleParser.cs b/src/Elastic.Markdown/Myst/Roles/RoleParser.cs index 6b76e9fed..42a8061de 100644 --- a/src/Elastic.Markdown/Myst/Roles/RoleParser.cs +++ b/src/Elastic.Markdown/Myst/Roles/RoleParser.cs @@ -31,7 +31,6 @@ public abstract class RoleParser : InlineParser public override bool Match(InlineProcessor processor, ref StringSlice slice) { - var match = slice.CurrentChar; if (processor.Context is not ParserContext) @@ -58,6 +57,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice) closeSticks++; i++; } + if (closeSticks > 1) return false; @@ -66,28 +66,25 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice) return false; // {role} has to be followed by `content` - if (span[i] != '`') - return false; - if (span.Length == i - 1) + if ((uint)i >= (uint)span.Length || span[i] != '`') return false; - var startContent = i; - i = span[(i + 1)..].IndexOfAny(['`']); - if ((uint)i >= (uint)span.Length) - return false; + var openingBacktickPos = i; + var contentStartPos = i + 1; // Skip the opening backtick - var closeBackTicks = 0; - while ((uint)i < (uint)span.Length && span[i] == '`') + var closingBacktickIndex = -1; + for (var j = contentStartPos; j < span.Length; j++) { - closeBackTicks++; - i++; + if (span[j] != '`') + continue; + closingBacktickIndex = j; + break; } - if (closeBackTicks > 1) + + if (closingBacktickIndex == -1) return false; - // Fix: Ensure we don't exceed the span length when calculating the end index - var endIndex = Math.Min(startContent + i + 2, span.Length); - var contentSpan = span[startContent..endIndex]; + var contentSpan = span[openingBacktickPos..(closingBacktickIndex + 1)]; var startPosition = slice.Start; slice.Start = startPosition + roleContent.Length + contentSpan.Length; @@ -100,7 +97,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice) var end = processor.GetSourcePosition(slice.Start); var sourceSpan = new SourceSpan(start, end); - var leaf = CreateRole(roleContent.ToString(), contentSpan.Trim().Trim('`').ToString(), processor); + var leaf = CreateRole(roleContent.ToString(), contentSpan.Trim('`').ToString(), processor); leaf.Delimiter = '{'; leaf.Span = sourceSpan; leaf.Line = line; From 6336273452e8ae7c550c5451d22176fd98a14f20 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 8 Jul 2025 00:08:49 +0200 Subject: [PATCH 2/2] Remove redundant check --- docs/testing/req.md | 3 +++ src/Elastic.Markdown/Myst/Roles/RoleParser.cs | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/testing/req.md b/docs/testing/req.md index 24cd5f6f9..95907215f 100644 --- a/docs/testing/req.md +++ b/docs/testing/req.md @@ -12,6 +12,9 @@ mapped_pages: stack: preview 9.0, ga 9.1 ``` +1. Select **Create** to create a new policy, or select **Edit** {icon}`pencil` to open an existing policy. +1. Select **Create** to create a new policy, or select **Edit** {icon}`logo_vulnerability_management` to open an existing policy. + {applies_to}`stack: preview 9.0` This tutorial is based on Elasticsearch 9.0. This tutorial is based on Elasticsearch 9.0. This tutorial is based on Elasticsearch 9.0. diff --git a/src/Elastic.Markdown/Myst/Roles/RoleParser.cs b/src/Elastic.Markdown/Myst/Roles/RoleParser.cs index 42a8061de..21b64613d 100644 --- a/src/Elastic.Markdown/Myst/Roles/RoleParser.cs +++ b/src/Elastic.Markdown/Myst/Roles/RoleParser.cs @@ -65,10 +65,6 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice) if (!Matches(roleContent)) return false; - // {role} has to be followed by `content` - if ((uint)i >= (uint)span.Length || span[i] != '`') - return false; - var openingBacktickPos = i; var contentStartPos = i + 1; // Skip the opening backtick