Skip to content

Commit a771e8c

Browse files
authored
Normalize substitution keys to be case-insensitive. (#380)
Substitution keys are now consistently converted to lowercase to ensure case-insensitive matching. This avoids potential mismatches caused by differing key casing in configurations and front matter.
1 parent 12f9ed1 commit a771e8c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Elastic.Markdown/Myst/ParserContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ public ParserContext(
4545
Configuration = configuration;
4646

4747
foreach (var (key, value) in configuration.Substitutions)
48-
Properties[key] = value;
48+
Properties[key.ToLowerInvariant()] = value;
4949

5050
if (frontMatter?.Properties is { } props)
5151
{
52-
foreach (var (key, value) in props)
52+
foreach (var (k, value) in props)
5353
{
54+
var key = k.ToLowerInvariant();
5455
if (configuration.Substitutions.TryGetValue(key, out _))
5556
this.EmitError($"{{{key}}} can not be redeclared in front matter as its a global substitution");
5657
else
5758
Properties[key] = value;
5859
}
59-
6060
}
6161

6262
if (frontMatter?.Title is { } title)

src/Elastic.Markdown/Myst/Substitution/SubstitutionParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
137137
startPosition -= openSticks;
138138
startPosition = Math.Max(startPosition, 0);
139139

140-
var key = content.ToString().Trim(['{', '}']);
140+
var key = content.ToString().Trim(['{', '}']).ToLowerInvariant();
141141
var found = false;
142142
var replacement = string.Empty;
143143
if (processor.Context?.Properties.TryGetValue(key, out var value) ?? false)

0 commit comments

Comments
 (0)