Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: File path fails when used in env vars on Windows [INS-4742] #8221

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/insomnia/src/templating/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,7 @@ export interface nunjucksTagContextMenuOptions extends Exclude<ReturnType<typeof
}

export const responseTagRegex = new RegExp('{% *response *.* %}');

export function sanitizeStrForWin32(str: string) {
return str.replace(/\\/g, '\\\\\\\\');
}
15 changes: 8 additions & 7 deletions packages/insomnia/src/ui/components/templating/tag-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import type { Workspace } from '../../../models/workspace';
import * as plugins from '../../../plugins';
import * as pluginContexts from '../../../plugins/context';
import * as templating from '../../../templating';
import type {
NunjucksParsedTag,
NunjucksParsedTagArg,
import {
type NunjucksParsedTag,
type NunjucksParsedTagArg,
sanitizeStrForWin32,
} from '../../../templating/utils';
import * as templateUtils from '../../../templating/utils';
import { useNunjucks } from '../../context/nunjucks/use-nunjucks';
Expand Down Expand Up @@ -104,7 +105,7 @@ export const TagEditor: FC<Props> = props => {
// Fix strings: arg.value expects an escaped value (based on updateArg logic)
for (const arg of activeTagData.args) {
if (typeof arg.value === 'string') {
arg.value = arg.value.replace(/\\/g, '\\\\');
arg.value = sanitizeStrForWin32(arg.value);
}
}
await Promise.all([
Expand Down Expand Up @@ -137,7 +138,7 @@ export const TagEditor: FC<Props> = props => {
}
// Fix strings
if (typeof argValue === 'string') {
argValue = argValue.replace(/\\/g, '\\\\');
argValue = sanitizeStrForWin32(argValue);
}
// Ensure all arguments exist
const defaultArgs = templateUtils.tokenizeTag(templateUtils.getDefaultFill(
Expand Down Expand Up @@ -342,7 +343,7 @@ export const TagEditor: FC<Props> = props => {
const encoding = argDefinition.encoding || 'utf8';
argInput = (<input
type="text"
defaultValue={strValue.replace(/\\\\/g, '\\') || ''}
defaultValue={sanitizeStrForWin32(strValue)}
placeholder={placeholder}
onChange={handleChange}
data-encoding={encoding}
Expand All @@ -365,7 +366,7 @@ export const TagEditor: FC<Props> = props => {
showFileName
className="btn btn--clicky btn--super-compact"
onChange={path => updateArg(path, index)}
path={strValue.replace(/\\\\/g, '\\')}
path={sanitizeStrForWin32(strValue)}
itemtypes={argDefinition.itemTypes}
extensions={argDefinition.extensions}
/>);
Expand Down
Loading