harden(vtag): exclude backslash from passthrough capture + parity tests (A review)

This commit is contained in:
Joseph Doherty
2026-06-07 15:31:54 -04:00
parent 08d7477860
commit b73ce75402
3 changed files with 62 additions and 1 deletions
@@ -76,4 +76,26 @@ public sealed class PassthroughScriptTests
PassthroughScript.TryMatch(source, out var tag).ShouldBeFalse();
tag.ShouldBe(string.Empty);
}
/// <summary>
/// A tag literal containing a backslash escape (C# source <c>"a\\b"</c> → runtime name
/// <c>a\b</c>) does NOT match the passthrough pattern — it falls through to Roslyn, which
/// interprets the escape and resolves the correct dependency key. Capturing the raw source
/// text <c>a\\b</c> would produce a wrong-result silent miss against the key <c>a\b</c>.
/// </summary>
[Fact]
public void Rejects_tag_literal_containing_backslash_escape()
{
// C# literal "return ctx.GetTag(\"a\\\\b\").Value;" → script source contains: a\\b (two chars: backslash + b)
PassthroughScript.TryMatch("return ctx.GetTag(\"a\\\\b\").Value;", out var tag).ShouldBeFalse();
tag.ShouldBe(string.Empty);
}
/// <summary>A plain dotted tag name (no backslash) still matches — the fix is additive only.</summary>
[Fact]
public void Matches_plain_dotted_tag_after_backslash_fix()
{
PassthroughScript.TryMatch("return ctx.GetTag(\"Site1.Area.Tag\").Value;", out var tag).ShouldBeTrue();
tag.ShouldBe("Site1.Area.Tag");
}
}