Skip to content

Commit 47e4d24

Browse files
authored
Fix RoleParser (#1536)
* Fix RoleParser * Remove redundant check
1 parent ad81fa4 commit 47e4d24

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

docs/testing/req.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ mapped_pages:
1212
stack: preview 9.0, ga 9.1
1313
```
1414

15+
1. Select **Create** to create a new policy, or select **Edit** {icon}`pencil` to open an existing policy.
16+
1. Select **Create** to create a new policy, or select **Edit** {icon}`logo_vulnerability_management` to open an existing policy.
17+
1518

1619
{applies_to}`stack: preview 9.0` This tutorial is based on Elasticsearch 9.0.
1720
This tutorial is based on Elasticsearch 9.0. This tutorial is based on Elasticsearch 9.0.

src/Elastic.Markdown/Myst/Roles/RoleParser.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public abstract class RoleParser<TRole> : InlineParser
3131

3232
public override bool Match(InlineProcessor processor, ref StringSlice slice)
3333
{
34-
3534
var match = slice.CurrentChar;
3635

3736
if (processor.Context is not ParserContext)
@@ -58,36 +57,30 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
5857
closeSticks++;
5958
i++;
6059
}
60+
6161
if (closeSticks > 1)
6262
return false;
6363

6464
var roleContent = slice.AsSpan()[..i];
6565
if (!Matches(roleContent))
6666
return false;
6767

68-
// {role} has to be followed by `content`
69-
if (span[i] != '`')
70-
return false;
71-
if (span.Length == i - 1)
72-
return false;
68+
var openingBacktickPos = i;
69+
var contentStartPos = i + 1; // Skip the opening backtick
7370

74-
var startContent = i;
75-
i = span[(i + 1)..].IndexOfAny(['`']);
76-
if ((uint)i >= (uint)span.Length)
77-
return false;
78-
79-
var closeBackTicks = 0;
80-
while ((uint)i < (uint)span.Length && span[i] == '`')
71+
var closingBacktickIndex = -1;
72+
for (var j = contentStartPos; j < span.Length; j++)
8173
{
82-
closeBackTicks++;
83-
i++;
74+
if (span[j] != '`')
75+
continue;
76+
closingBacktickIndex = j;
77+
break;
8478
}
85-
if (closeBackTicks > 1)
79+
80+
if (closingBacktickIndex == -1)
8681
return false;
8782

88-
// Fix: Ensure we don't exceed the span length when calculating the end index
89-
var endIndex = Math.Min(startContent + i + 2, span.Length);
90-
var contentSpan = span[startContent..endIndex];
83+
var contentSpan = span[openingBacktickPos..(closingBacktickIndex + 1)];
9184

9285
var startPosition = slice.Start;
9386
slice.Start = startPosition + roleContent.Length + contentSpan.Length;
@@ -100,7 +93,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
10093
var end = processor.GetSourcePosition(slice.Start);
10194
var sourceSpan = new SourceSpan(start, end);
10295

103-
var leaf = CreateRole(roleContent.ToString(), contentSpan.Trim().Trim('`').ToString(), processor);
96+
var leaf = CreateRole(roleContent.ToString(), contentSpan.Trim('`').ToString(), processor);
10497
leaf.Delimiter = '{';
10598
leaf.Span = sourceSpan;
10699
leaf.Line = line;

0 commit comments

Comments
 (0)