fix(scripting): {{equip}} substitution escapes the RawPath it pastes into the string literal
A RawPath segment may contain backslash, quote, braces, line breaks or non-ASCII text. SubstituteEquipmentToken pasted it raw into a regular C# string literal, so a device named de\qv failed to compile and x\vy silently read a different tag path (\v became a vertical tab). The paste is now encoded (EscapeForRegularLiteral) and the <RefName> / dependency refs are decoded (TryDecodeRegularLiteral), so GetTag receives the exact RawPath at both compose seams and the mux subscribes to the real key. The path-literal regex is escape-aware. The Monaco OTSCRIPT_EQUIPREF diagnostic and completion share the same scan/escape. The deploy gate's SubstitutionPreservesCompilation is now a verified round trip, so its pinned device-name case flips from rejected to accepted.
This commit is contained in:
@@ -498,6 +498,28 @@ the path is a normal string literal. An unresolved ref is left un-substituted (t
|
||||
validator rejects it first — substitution never throws). The two seams build the
|
||||
reference map identically, so their plans stay byte-parity.
|
||||
|
||||
**The paste is escaped (string-literal rule).** The path literal is a C# *regular* string
|
||||
literal, so its content is source text, not the string value, and a RawPath segment may legally
|
||||
hold `\`, `"`, braces, line breaks or non-ASCII text (`RawPaths.ValidateSegment` only forbids
|
||||
`/` and edge whitespace). Substitution therefore treats the literal exactly as the compiler does:
|
||||
|
||||
- the `<RefName>` is **decoded** (C# escapes resolved) before the map lookup, so a reference named
|
||||
`a\b` is written `{{equip}}/a\\b`, and one named `q"t` is written `{{equip}}/q\"t`;
|
||||
- the resolved RawPath is **encoded** (`EquipmentScriptPaths.EscapeForRegularLiteral`: `\` and `"`
|
||||
backslash-escaped; CR/LF/U+0085/U+2028/U+2029, other control characters and unpaired surrogates as
|
||||
`\uXXXX`; braces and non-ASCII untouched) when it is pasted back, so `GetTag` receives the exact
|
||||
RawPath — a device named `de\qv` neither breaks compilation nor, for `x\vy`, silently turns
|
||||
`\v` into a vertical tab;
|
||||
- `ExtractDependencyRefs` (the mux subscription keys) decodes the same way, so the dependency
|
||||
ref is the runtime string value, not the escaped source text;
|
||||
- the editor's `OTSCRIPT_EQUIPREF` diagnostic and completion use the same scan
|
||||
(`EquipmentScriptPaths.FindEquipReferenceLiterals`), and completion inserts the escaped form.
|
||||
|
||||
A `<RefName>` with a malformed escape (`\e`) is left as written for the compiler to report. Only
|
||||
regular `"…"` literals are path literals: a `{{equip}}/…` token inside a verbatim (`@"…"`),
|
||||
interpolated (`$"…"`) or raw (`"""…"""`) literal is **not substituted** (and not checked) — keep the
|
||||
token in a regular literal.
|
||||
|
||||
---
|
||||
|
||||
## Input quality: what a script sees, and when it runs at all
|
||||
|
||||
Reference in New Issue
Block a user