Skip to content

Commit

Permalink
fix: file paths fail on Windows [INS-4742]
Browse files Browse the repository at this point in the history
  • Loading branch information
filfreire committed Dec 13, 2024
1 parent 1910b34 commit f74ce3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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(path: string) {
return path.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 {
sanitizeStrForWin32,
type NunjucksParsedTag,
type NunjucksParsedTagArg,
} 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

0 comments on commit f74ce3c

Please sign in to comment.