Escaping characters when using the two -folders <list> variants

Discussion related to "Everything" 1.5 Alpha.
Post Reply
GSD
Posts: 30
Joined: Fri Apr 28, 2023 12:59 pm

Escaping characters when using the two -folders <list> variants

Post by GSD »

I'm having trouble with both the semicolon seaprated list and JSON-like varaints of the -folders <list> command line command.
There are probably other valid file/fodler name characters that cause trouble, but these are the ones I've found:
- , and ; for the semicolon list
- {} for the JSON-like variant

How should we escape such characters in either variant?

Furthermore, I may be wrong, but I feel like the "JSON-like" variant(which I would always prefer for it's added flexibility) would be better off using proper json decode, so we could just use json encode on the other end. Right now, I'm doing this in Powershell:

Code: Select all

$encodedFolders = ($folders | ConvertTo-Json -Compress).Replace('\\','\')
This is so the escaping from \ to \\, that PS's json encoder does, does not reflect in the resulting string. The fact that this needs doing makes me think that Everything is not using a proper json decoder on the other end. And a valid json decoder would have no issue with any character, so long as it gets served a valid json string.
void
Developer
Posts: 16775
Joined: Fri Oct 16, 2009 11:31 pm

Re: Escaping characters when using the two -folders <list> variants

Post by void »

Thank you for the issue report GSD,

Please use double quotes (") to escape special characters.
\ is the escape character while inside double quotes.
\\ = \
\" = "

For example:
folders="C:\\Program Files";"C:\\Windows";"C:\\A;path;with;semicolons"

List Syntax



As for JSON, please make sure the values are double quoted.

For example:
folders=[{"path":"C:\\Program Files","fast_update":1},{"path":"C:\\Windows","fast_update":1},{"path":"C:\\A{path}with;special-characters"}]

I am seeing valid JSON from Help -> Troubleshooting information -> Folders.

Could you please send the value of $encodedFolders to support@voidtools.com
How are you passing this information to Everything?
From the command line? (please check Help -> Troubleshooting information -> Command line)
Everything is most likely unescaping this JSON value somewhere..

I am looking into powershell ConvertTo-Json -Compress..
GSD
Posts: 30
Joined: Fri Apr 28, 2023 12:59 pm

Re: Escaping characters when using the two -folders <list> variants

Post by GSD »

Hello @void and thank you for your reply!

In both instances I am refering to using the "-folders" parameter via the command line(powershell) and not directly editing the main .ini file.

(all code below is in Powershell)

To replicate for the list syntax:

Code: Select all

$foldersArray = "c:\first path; with semicolon, and colon", "c:\second path"
$foldersString = "`"$($foldersArray -join '`";`"')`""
echo "SEARCH STRING IS: $foldersString"
./Everything64.exe -folders "$foldersString"
Troubleshooting info reports:

Code: Select all

Command line:	-folders "c:\first path; with semicolon, and colon";"c:\second path"
Resulting .ini file contains:

Code: Select all

folders=and colon,c:\first path,c:\second path,with semicolon
To replicate for the "JSON-like" syntax:

Code: Select all

$foldersArray = "c:\first path {with curly brackets}", "c:\second path"
$folders = @()
foreach ($path in $foldersArray) {
    $folders += [ordered]@{
        "path" = "$path"
        "subfolders" = 1
    }
}
$encodedFolders  = ($folders | ConvertTo-Json -Compress).Replace('\\','\')
echo "ENCODED FOLDERS JSON IS: $encodedFolders"
./Everything64.exe -folders "$encodedFolders"
Troubleshooting info reports:

Code: Select all

Command line:	-folders [{"path":"c:\first path {with curly brackets}","subfolders":1},{"path":"c:\second path","subfolders":1}]
Resulting .ini file contains:

Code: Select all

folders=c:\first path {with curly brackets,c:\second path,subfolders:1}
Regarding the JSON-decode that Everyhting is doing(possibly unrelated to the above issues):
If we remove the problematic charactes from the paths(for simplicity) and remove ".Replace('\\','\')", so we have properly escaped JSON

Code: Select all

$foldersArray = "c:\first path", "c:\second path"
$folders = @()
foreach ($path in $foldersArray) {
    $folders += [ordered]@{
        "path" = "$path"
        "subfolders" = 1
    }
}
$encodedFolders  = ($folders | ConvertTo-Json -Compress)
echo "ENCODED FOLDERS JSON IS: $encodedFolders"
./Everything64.exe -folders "$encodedFolders"
Troubleshooting info reports:

Code: Select all

Command line:	-folders [{"path":"c:\\first path","subfolders":1},{"path":"c:\\second path","subfolders":1}]
Resulting .ini file contains:

Code: Select all

folders=c:\\first path,c:\\second path
Seems like "\\" is not getting properly unescaped. This is what led me to believe that Everything is not doing a proper JSON decode, as that should include unescaping, correct?
void
Developer
Posts: 16775
Joined: Fri Oct 16, 2009 11:31 pm

Re: Escaping characters when using the two -folders <list> variants

Post by void »

Please escape double quotes.

Everything will see:

Code: Select all

-folders [{"path":"c:\\first path","subfolders":1},{"path":"c:\\second path","subfolders":1}]
as:

Code: Select all

-folders "[{path:c:\\first path,subfolders:1},{path:c:\\second path,subfolders:1}]"
(single double quotes only escape spaces)



Everything's json decoder is very forgiving and ignores the missing quotes.
\ is only used as an escape character when inside double quotes.

Please escape a single double quote with three double quotes. (""")



For example:

Code: Select all

-folders "[{"""path""":"""c:\\first path""","""subfolders""":1},{"""path""":"""c:\\second path""","""subfolders""":1}]"



The easiest way I found to do this from powershell:

Code: Select all

$argv='-folders "'+$encodedFolders.replace('"','"""')+'"'
Then launch Everything with:

Code: Select all

Start-Process -FilePath 'c:\Program Files\Everything-1.5a\Everything64.exe' -ArgumentList $argv


The next alpha update will have support for:

Code: Select all

-folders* [{"path":"c:\\first path","subfolders":1},{"path":"c:\\second path","subfolders":1}]
(note the * after -folders, which treats the rest of the command line as literal)
GSD
Posts: 30
Joined: Fri Apr 28, 2023 12:59 pm

Re: Escaping characters when using the two -folders <list> variants

Post by GSD »

void wrote: Wed Jun 07, 2023 6:10 am The next alpha update will have support for:

Code: Select all

-folders* [{"path":"c:\\first path","subfolders":1},{"path":"c:\\second path","subfolders":1}]
(note the * after -folders, which treats the rest of the command line as literal)
Excellent! Thank you!
GSD
Posts: 30
Joined: Fri Apr 28, 2023 12:59 pm

Re: Escaping characters when using the two -folders <list> variants

Post by GSD »

Hello again @void,

I've switched gears for a bit and found a different approach, which seems cleaner to me:

Code: Select all

$foldersArray = "c:\first path {with curly brackets}", "c:\second path"
$encodedFolders = $foldersArray -join ','
$argv = "-config-value folders=`"$encodedFolders`""
Start-Process -FilePath 'c:\Program Files\Everything-1.5a\Everything64.exe' -ArgumentList $argv
Are there any caveats with this approach?
void
Developer
Posts: 16775
Joined: Fri Oct 16, 2009 11:31 pm

Re: Escaping characters when using the two -folders <list> variants

Post by void »

You'll run into the same issues with double quotes being ignored and folders with a comma (,) not working.
GSD
Posts: 30
Joined: Fri Apr 28, 2023 12:59 pm

Re: Escaping characters when using the two -folders <list> variants

Post by GSD »

void wrote: Sun Jun 11, 2023 11:27 pm You'll run into the same issues with double quotes being ignored and folders with a comma (,) not working.
Right! It completly slipped my mind that comma is valid in folder/filenames :D

Well, for the time beeing, your solution using "Start-Process" is working well. I was never able to get that working by invoking Everything directly, but it seems "Start-Process -ArgumentList" saves a lot of headaches with how it processes(or not, to be more precise) said arguments string. So thank you for that!
void
Developer
Posts: 16775
Joined: Fri Oct 16, 2009 11:31 pm

Re: Escaping characters when using the two -folders <list> variants

Post by void »

Everything 1.5.0.1351a adds * support to all command line options.

For example:
-folders* [{"path":"c:\\first path","subfolders":1},{"path":"c:\\second path","subfolders":1}]
GSD
Posts: 30
Joined: Fri Apr 28, 2023 12:59 pm

Re: Escaping characters when using the two -folders <list> variants

Post by GSD »

Tested and working. Thank you!
Post Reply