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
@@ -7,10 +7,17 @@ using System.Text.RegularExpressions;
/// which can be evaluated by returning the dependency value directly — no Roslyn compilation.
/// Narrow, exact pattern: any near-miss returns false and falls through to the Roslyn path.
/// </summary>
/// <remarks>
/// Physically defined in the Core.Scripting.Abstractions assembly (Roslyn-free, so ControlPlane
/// can reference it); the namespace is Core.Scripting to keep consumer using-directives unchanged.
/// </remarks>
public static partial class PassthroughScript
{
// ^ \s* return \s+ ctx . GetTag ( "X" ) . Value ; \s* $ (whitespace-tolerant around tokens)
[GeneratedRegex(@"^\s*return\s+ctx\s*\.\s*GetTag\s*\(\s*""([^""]+)""\s*\)\s*\.\s*Value\s*;\s*$")]
// Tag-name class [^"\\] excludes both the closing quote and backslash: a literal containing a
// backslash escape (e.g. "a\\b" → runtime name a\b) won't match, so it correctly falls through
// to Roslyn, which interprets the escape and resolves the actual dependency key.
[GeneratedRegex(@"^\s*return\s+ctx\s*\.\s*GetTag\s*\(\s*""([^""\\]+)""\s*\)\s*\.\s*Value\s*;\s*$")]
private static partial Regex MirrorRegex();
/// <summary>True if <paramref name="source"/> is the mirror passthrough shape; outputs the referenced tag.</summary>