ID:139781
 
Code:
  var/filepath = winget(usr, "MyInput", "text")
world.log << filepath


Problem description:
This works fine until I come across a file with \t somewhere in the path and then the \t gets turned into a tab.

I've been adding double quotes, single quotes, url_encode, and yadda yadda... I forgot how to properly handle this. Can someone help?

I've solved this before but I can't locate the project I did it in.

ts

I've been stuck half the day on this... :|

Step 1 - User enters this in an input and clicks submit
C:\MyFiles\tibby.png


Step 2 - I output the path to world
world >> winget(usr, "controlID", "text")


Step 3 - The result
C:\MyFiles


How can I preserve the full file path?
ts
In response to Tsfreaks
Tsfreaks wrote:
This works fine until I come across a file with \t somewhere in the path and then the \t gets turned into a tab.

If the \t is being turned into a tab then you would probably want to use html_encode if I was to guess. Just a shot in the dark though.
In response to AJX
Yeah, I tried it. It doesn't encode \n \t etc. Thanks for suggestion though. Starting to bang my head on the desk because this is getting silly...

ts
In response to Tsfreaks
Not sure why it wouldn't. I'm assuming the variable is being stored properly in its entirety and when you broadcast it to the world it is being parsed to have the tab. Are you using encode when it is being world<<'d or when you're storing the variable?

Worst case scenario you could parse it manually into \\ instead of \.


EDIT: Tested it.. Not sure why html_encode isn't stripping out the \t. The only thing I can suggest at this point is to just parse the text to replace any stand-alone '\'s with '\\'
In response to AJX
This is all the test code. The interface has an input where the user enters a path. I've tried a ton of stuff around the winget.

alert(winget(usr, "ImageInput", "text"))


ts
In response to Tsfreaks
Yea I tried encode()'ing any text with slash macros and it doesn't. Like I said, just run the text through a parser to replace any stand-alone '\'s with '\\', which will in turn make it a normal backslash instead of one used for macro purposes.
In response to AJX
Well, I had tried that and the problem is that the \t (tab) problem happens right from the get-go. The winget return value looks like this.

c:\asdfsadf         asdfasdfsdf.htm


Again, it should look like
c:\asdfsadf\tasdfasdfsdf.htm


You have to replace the \t with \\ which works... but then you have to do the \n and god knows what else. I was hoping to avoid that because I thought there has to be an easier way. It would be nuts for this to be such a chore.

ts
In response to Tsfreaks
Tsfreaks wrote:
You have to replace the \t with \\ which works... but then you have to do the \n and god knows what else.

You should be okay with only replacing "\" with "\\". This would make the string "path\test" become "path\\test". The first slash escapes the second to create the "\\" macro followed by a "t" instead of the "\t" macro. This gets around \n and other things like it too.
In response to Forum_account
Right... but it doesn't work!?

var/filePath = dd_replacetext(winget(usr, "ImageInput", "text"), "\\", "\\\\");


replacetext comes from deadrons texthandling library and replaces all the back slashes except for anywhere a \t and \n exist because they were already converted into a tab or new line by the time I can replace them.

Am I doing something wrong here?
ts
In response to Tsfreaks
Ah, I see now. It doesn't seem like there's a nice way to handle this.

The string should be coming to you with the "\t" already escaped as "\\t". The string should only contain "\t" if you typed a tab in the input box and should contain "\\t" if you literally typed "\t". You should submit a bug report for this.
In response to Forum_account
I'm pretty sure that getting a file path from a user cannot be impossible. That can't be right. Lummox will pop on, declare my bug as dumb and set me straight.

ts

In response to Tsfreaks
The literal string "\t" and a tab character are both returned to you as a tab. For the sake of file names you can assume that the name doesn't contain a tab character so you can convert all tabs to the literal "\t". In general, however, receiving a tab character in the contents of an input box gives you no way of telling if the user typed in a tab or "\t".

I certainly hope this isn't the intended behavior, but this wouldn't be the first time I've said that about winset and winget.