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

[Bug] Can't load file for file token #757

Closed
Mardoxx opened this issue Feb 13, 2018 · 9 comments · Fixed by #2708
Closed

[Bug] Can't load file for file token #757

Mardoxx opened this issue Feb 13, 2018 · 9 comments · Fixed by #2708
Labels
B-bug Bug: general classification E-good-first-issue Experience required: Beginner / New

Comments

@Mardoxx
Copy link

Mardoxx commented Feb 13, 2018

  • Insomnia Version: 5.14.3
  • Operating System: win10

Details

  1. Create request
  2. Add a file token and click it
  3. Choose file click Done
  4. File token is in warning state

Quick look at error message says:
ENOENT: no such file or directory, open 'C:\Users\Owner\AppData\Local\insomnia\app-5.14.6\UsersOwnerDesktopimage.png'

So looks like it's resolving file path wrongly!

Thanks 😄

@welcome
Copy link

welcome bot commented Feb 13, 2018

👋 Thanks for opening your first issue! If you're reporting a 🐞 bug, please make sure
you include steps to reproduce it. If you're requesting a feature 🎁, please provide real
use cases that would benefit. 👪

To help make this a smooth process, please be sure you have first read the
contributing guidelines.

@Mardoxx
Copy link
Author

Mardoxx commented Feb 13, 2018

Another thing to note is that the live preview takes literally minutes to load and is blocking and eventually hangs and crashes the app for any file over a few KB.

@Mardoxx
Copy link
Author

Mardoxx commented Feb 13, 2018

Exporting data shows path of

"value": "{% file 'C:\\\\Users\\\\Owner\\\\Desktop\\\\image.png' %}"

If I change this to

"value": "{% file 'C:/Users/Owner/Desktop/image.png' %}"

it works fine.

This, however, breaks also.

"value": "{% file 'C:\\Users\\Owner\\Desktop\\image.png' %}"

HTH..

@gschier
Copy link
Contributor

gschier commented Feb 15, 2018

Hmm, I hesitate to simply replace all backslashes with forward slashes. I assume this hack would break if a file or folder name contained a forward slash?

It would be nice to figure out the actual cause of this issue. I don't currently have a Windows machine set up for development. Any chance you'd be interested in working on a fix for this?

@gschier gschier changed the title Can't load file for file token [Bug] Can't load file for file token Feb 15, 2018
@gschier gschier added E-good-first-issue Experience required: Beginner / New N-help Needs: Help Accepted labels Feb 15, 2018
@Mardoxx
Copy link
Author

Mardoxx commented Feb 15, 2018

Sure, I'll give it a go 😄

@gschier
Copy link
Contributor

gschier commented Feb 15, 2018

In case you want/need a place to start... I'd first figure out if the value of path here is what you expect: https://github.com/getinsomnia/insomnia/blob/b3e473071824f0e48e7c26507163182acbe01703/plugins/insomnia-plugin-file/index.js#L18

@Mardoxx
Copy link
Author

Mardoxx commented Feb 15, 2018

Thanks, saved me digging 😄

@thewheat
Copy link
Contributor

thewheat commented Oct 4, 2020

I believe I've replicated the root cause on MacOS as well when having a file with a backslash in it. Happy to try fix this but digging into the code it seems there is some tokenization and untokenization which could be the root cause as I do see some backslash handling/manipulations

if (!argCompleted && currentArg !== null) {
if (c === '\\') {
// Handle backslashes
i += 1;
currentArg += argsStr.charAt(i);
} else {
currentArg += c;
}
}

/** Convert a tokenized tag back into a Nunjucks string */
export function unTokenizeTag(tagData: NunjucksParsedTag): string {
const args = [];
for (const arg of tagData.args) {
if (['string', 'model', 'file', 'enum'].includes(arg.type)) {
const q = arg.quotedBy || "'";
const re = new RegExp(`([^\\\\])${q}`, 'g');
const str = arg.value.toString().replace(re, `$1\\${q}`);
args.push(`${q}${str}${q}`);
} else if (arg.type === 'boolean') {
args.push(arg.value ? 'true' : 'false');
} else {
args.push(arg.value);
}
}
const argsStr = args.join(', ');
return `{% ${tagData.name} ${argsStr} %}`;
}

Select file with Backslash
image

Initial loading and preview works
image

Bring up modal again and preview doesn't work
image

Request works
The request using the file selected still works so the problem looks to be related to the display/preview
image


This problem seems to be an issue with backslashes in general as a similar problem shows up when trying to Base64encode (similar to above, requests sents do have the correct data, so the problem lies in the just the view portion it seems)

image

@wdawson wdawson closed this as completed Jun 30, 2021
@Kong Kong locked and limited conversation to collaborators Jun 30, 2021
@wdawson wdawson removed the N-help Needs: Help label Jul 1, 2021
@Kong Kong unlocked this conversation Jul 1, 2021
@wdawson
Copy link
Contributor

wdawson commented Jul 1, 2021

Sorry folks! This was incorrectly tagged as a feature request along with other bugs. I'm going back through and cleaning up, sorry for the inconvenience.

@wdawson wdawson reopened this Jul 1, 2021
@wdawson wdawson added the B-bug Bug: general classification label Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-bug Bug: general classification E-good-first-issue Experience required: Beginner / New
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants