Skip to content

fix: bracket-quote pm variable names that aren't valid identifiers - #10604

Merged
cwangsmv merged 1 commit into
developfrom
fix/transfer-and-support-pm-variable-with-invalid-identifier-name
Oct 19, 2026
Merged

cwangsmv merged 1 commit into
developfrom
fix/transfer-and-support-pm-variable-with-invalid-identifier-name

Conversation

@cwangsmv

@cwangsmv cwangsmv commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PM variable names can contain invalid identifiers ({{var Space}}, {{1st}}, {{a/b}}), but
Insomnia renders {{name}} as a plain lookup, which only works for identifier-like names. Previously
normaliseJsonPath only rewrote names containing -, so every other special name imported unchanged and
failed to resolve.

normaliseJsonPath now rewrites any {{ name }} whose name is not a valid identifier to {{ _['name'] }}. Valid names are left untouched.

INS-3935

@cwangsmv
cwangsmv marked this pull request as draft October 15, 2026 03:23
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ KSAI Review: Finished

  1. 03:27 UTC Reviewing the changed files and patch for issues
  2. 03:29 UTC Reviewing templating and importer changes for correctness
  3. 03:31 UTC Tracing template rendering behavior through code and tests
  4. 03:33 UTC Tracing template variable handling across the templating code paths
  5. 03:35 UTC The agent is working: tracing template variable handling across importer and engine code
  6. 03:39 UTC Tracing template variable handling and auditing review findings

Run report (federated) · 1 paid run · $0.1006 total
# Engine Result Model Turns Cost
1 opencode success glm-5.3-flash/max 38 $0.1000

Reviewing cost $0.1000; deciding how to run it cost $0.0006

@cwangsmv
cwangsmv marked this pull request as ready for review October 15, 2026 03:35
@cwangsmv
cwangsmv requested a balanced review from Copilot October 15, 2026 03:36

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check Result
Scope Postman importer reference normalisation (normaliseJsonPath) and its unit tests
Mandate typescript-code-reviewer (typescript-code-review)
Findings 3 Low
Findings audit Audited by findings-auditor subagent: F1 downgraded Medium to Low (pre-existing, engine premise unverifiable in tree), F2 kept with corrected output string, F3 merged into F2 replacement, F4 kept. No missed bugs, all anchors verified.

The rewrite correctly widens bracket-notation normalisation to every non-identifier Postman reference. Traced regex captures and quote escaping match all asserted outputs; _ is bound to the render context, so the single-wrap form resolves.

Additional Risk pass: No additional concerns found. No secrets, injection, or resource issues in the two changed files.

Comment thread packages/insomnia/src/main/importers/importers/postman.ts
Comment thread packages/insomnia/src/main/importers/importers/postman.ts
Comment thread packages/insomnia/src/main/importers/importers/postman.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved import regressions affect GraphQL body serialization and variable resolution.

3 open findings
What changed in this PR

Expands Postman variable conversion so names containing spaces, dots, leading digits, and other non-identifier characters use bracket notation.

Changes:

  • Replaces dash-only normalization with identifier validation.
  • Adds tests for special names, mixed references, and unchanged text.
File Description
packages/​insomnia/​src/​main/​importers/​importers/​postman.ts Expands variable-name normalization.
packages/​insomnia/​src/​main/​importers/​importers/​postman.test.ts Adds focused normalization tests.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/insomnia/src/main/importers/importers/postman.ts
return `{{${replaced}}}`;
return input.replace(/{{\s*([^{}]*?)\s*}}/g, (match, name: string) => {
// If the name is empty or a valid identifier, leave it as is.
if (!name || VALID_IDENTIFIER.test(name)) {
return match;
}
// Otherwise, force bracket notation for the name.
return `{{${forceBracketNotation('_', name)}}}`;
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ KSAI Review: Finished

  1. 03:43 UTC Reviewing template engine and importer test behavior
  2. 03:45 UTC Auditing templating changes and tracing related code paths
  3. 03:47 UTC Tracing template engine behavior against importer changes in the diff
  4. 03:49 UTC Tracing template rendering behavior and compatibility test coverage

Run report (federated) · 1 paid run · $0.0734 total
# Engine Result Model Turns Cost
1 opencode success glm-5.3-flash/max 33 $0.0729

Reviewing cost $0.0729; deciding how to run it cost $0.0005

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check Result
Scope Postman importer: variable-reference normalisation (identifier whitelist gate, bracket-notation rewrite) and its unit tests
Mandate typescript-code-reviewer
Findings 1 Medium, 1 Low
Findings audit One findings-auditor subagent verified both findings against the code: Finding 1 downgraded High to Medium with reworded body, Finding 2 upheld, no missed bugs.

The rewrite fixes real gaps in the old dash-only rewriter, and the tests pin the new outputs. The whitelist follows ECMAScript identifier rules, not the LiquidJS grammar the strings render under. Non-ASCII names are the exposed case.

Additional Risk pass found nothing: no secrets, no new injection surface, no leak or growth risks.


// old: {{ arr-name-with-dash }}
// new: {{ _['arr-name-with-dash'] }}
const VALID_IDENTIFIER = /^[\p{ID_Start}_$][\p{ID_Continue}$\u200C\u200D]*$/u;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Medium bug

VALID_IDENTIFIER accepts names by ECMAScript identifier rules. The engine is LiquidJS (package.json: liquidjs ^10.27.0), whose lexer accepts ASCII identifiers only — unverified against the installed source. An imported variable named 中文字符 stays as {{中文字符}}, so render throws instead of resolving, and postman.test.ts:57-59 codifies it. Bracket form _['中文字符'] renders (liquid-compat.test.ts:41-42). Fix: scope the regex to the engine's grammar; non-ASCII names get bracket notation; foo, _bar1, $randomInt keep passing.

Suggested change
const VALID_IDENTIFIER = /^[\p{ID_Start}_$][\p{ID_Continue}$\u200C\u200D]*$/u;
const VALID_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;

React 👍 if this finding helped, 👎 if it did not.

Comment on lines +111 to +116
// If the name is empty or a valid identifier, leave it as is.
if (!name || VALID_IDENTIFIER.test(name)) {
return match;
}
// Otherwise, force bracket notation for the name.
return `{{${forceBracketNotation('_', name)}}}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low delete

Both comments restate the adjacent if/else: the condition line and the return say the same. The why lives in the block comment at postman.ts:99-102, and the empty-capture branch is pinned by postman.test.ts:76. Remove them.

Suggested change
// If the name is empty or a valid identifier, leave it as is.
if (!name || VALID_IDENTIFIER.test(name)) {
return match;
}
// Otherwise, force bracket notation for the name.
return `{{${forceBracketNotation('_', name)}}}`;
if (!name || VALID_IDENTIFIER.test(name)) {
return match;
}
return `{{${forceBracketNotation('_', name)}}}`;

React 👍 if this finding helped, 👎 if it did not.

@cwangsmv
cwangsmv enabled auto-merge (squash) October 19, 2026 07:18
@cwangsmv
cwangsmv force-pushed the fix/transfer-and-support-pm-variable-with-invalid-identifier-name branch from d37d51c to f4ae274 Compare October 19, 2026 07:18
@cwangsmv
cwangsmv merged commit a7eb494 into develop Oct 19, 2026
21 checks passed
@cwangsmv
cwangsmv deleted the fix/transfer-and-support-pm-variable-with-invalid-identifier-name branch October 19, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants