fix: Update the vault tag id when paste the vault tag - #10402
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses duplicated external vault tag IDs when users copy/paste vault template tags, by regenerating fresh IDs during paste so each pasted tag links to a distinct credential mapping.
Changes:
- Added external-vault tag ID detection and replacement helpers in templating utilities.
- Updated CodeMirror-based editors to regenerate vault tag IDs on paste (both single-line and multi-line editors).
- Refactored legacy vault tag conversion to use the shared ID generator and added unit tests for the replacement logic.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/insomnia/src/ui/components/templating/tag-editor.tsx | Switches legacy vault tag conversion to the shared external vault tag ID generator. |
| packages/insomnia/src/ui/components/.client/codemirror/one-line-editor.tsx | Adds paste handling to detect vault tags and regenerate IDs in single-line editor content. |
| packages/insomnia/src/ui/components/.client/codemirror/code-editor.tsx | Adds paste handling to regenerate vault tag IDs (and preserves existing onPaste behavior). |
| packages/insomnia/src/common/templating/utils.ts | Introduces external vault tag ID prefix, generator, detection, and replacement implementation. |
| packages/insomnia/src/common/templating/tests/utils.test.ts | Adds unit tests for vault tag ID replacement behavior. |
| packages/insomnia/src/common/constants.ts | Adds an exported prefix constant for external vault tag IDs. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (3)
packages/insomnia/src/ui/components/.client/codemirror/one-line-editor.tsx:218
change.text.join('')removes line boundaries before thereplace(/\n/g, ' ')runs, so multi-line paste content gets concatenated without spaces (e.g. "a\nb" -> "ab"). Since this is the single-line editor, it should preserve boundaries by joining with newlines (or spaces) before collapsing to a single line.
let editorPasteText = change.text.join('').replace(/\n/g, ' ');
if (containsExternalVaultTag(editorPasteText)) {
editorPasteText = replaceVaultTagIdIfNeeded(editorPasteText);
}
// If we're in single-line mode, merge all changed lines into one
packages/insomnia/src/common/templating/utils.ts:180
vaultTagIdRegexis exported with the global (g) flag. Global regexes are stateful when used withRegExp.test()(and some matchers), which can lead to flaky behavior across repeated calls. Consider exporting a non-global regex and using a local global clone only where replacement needs it.
const tagRegex = /{%[\s\S]+?%}/g;
export const vaultTagIdRegex = new RegExp(`${externalVaultTagPrefix}_[a-z0-9]{32}`, 'g');
export const containsExternalVaultTag = (input: string) => {
packages/insomnia/src/ui/components/.client/codemirror/one-line-editor.tsx:207
isPasteis currently assignedchange.origin === 'paste' && change.update, which can evaluate to theupdatefunction instead of a boolean. This works at runtime but is confusing for typing and future maintenance; consider making the condition explicitly boolean (or inlining the condition).
codeMirror.current.on('beforeChange', (_: CodeMirror.Editor, change: CodeMirror.EditorChangeCancellable) => {
const isPaste = change.origin === 'paste' && change.update;
if (isPaste) {
77f46f3 to
6cb8d50
Compare
6cb8d50 to
f1aa109
Compare
f1aa109 to
dbb5569
Compare
Background:
Each vault tag has a unique ID that establishes the relationship between the tag and the user-selected vault credential record in the database.
However, when a user copies and pastes a vault tag, the duplicated tags will share the same unique ID. As a result, modifying the credential record linked to one tag can unintentionally affect the other vault as well.
Changes:
INS-3535