-
Notifications
You must be signed in to change notification settings - Fork 104
Description
When using documentUrlSubstitutions with a custom parser, the CLI applies substring replacement to template file content. This causes incorrect URL substitutions when one key is a prefix of another.
Problem
The substitution logic at
code-connect/cli/src/html/parser.ts
Line 592 in 5e3d6c5
| figmaNode = figmaNode.replace(from, to) |
String.replace():
Object.entries(config.documentUrlSubstitutions).forEach(([from, to]) => {
figmaNode = figmaNode.replace(from, to)
}) This performs substring matching rather than exact matching. When two keys share a common prefix, the shorter key can partially match within the longer
key's value, corrupting the URL.
Reproduction
Config:
{
"documentUrlSubstitutions": {
"SearchInput": "https://figma.com/file/abc/?node-id=4307-49807",
"SearchInputMenu": "https://figma.com/file/abc/?node-id=15100-76317"
}
} Template file:
// url=SearchInputMenu
Expected: URL resolves to https://figma.com/file/abc/?node-id=15100-76317
Actual: The CLI first applies SearchInput substitution (substring match), resulting in:
https://figma.com/file/abc/?node-id=4307-49807Menu
This produces the error:
Invalid figma node URL: the provided node-id "4307-49807Menu" is invalid
Environment
- @figma/code-connect version: 1.4.1
- Parser: custom
- Platform: macOS