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

special characters #68

Open
paponius opened this issue Jun 28, 2018 · 2 comments
Open

special characters #68

paponius opened this issue Jun 28, 2018 · 2 comments

Comments

@paponius
Copy link

Names of files processed by Minify plugin can't contain Special characters (, ).
Also, more special character, like * can't be used in arguments.
environment: Windows
possible solution:

  • check escaping of ( )
  • avoid CMD shell

I also included my work-around.
Although it can't be used to fix the problem, maybe it will come useful for testing the issue.
Or for someone to use it as a workaround.

I was not able to un-minify files which name include brackets: assets_manifest (8).min.js
It's also not possible to use * to define comments to remove in plugin option file: "comments_to_keep": "/^(?!XXX).*$/"

The error dialog shows that brackets are being escaped ^^(8^^), but this doesn't do the trick, at least on my PC.

node.js doesn't have a problem with these characters, they only needs to be escaped/avoided
because of a CMD (BAT) file, or more specifically CMD shell.
The process is, that
Minify plugin by default calls uglifyjs, Windows will find uglifyjs.cmd in a folder added to PATH environment variable.
Here: C:\Users\Papo\AppData\Roaming\npm\uglifyjs.cmd
this bat will in return call: node "%~dp0\node_modules\uglify-js\bin\uglifyjs" %*

To avoid the CMD shell, I tried to define the command in Minify plugin:
"uglifyjs_command": "node C:\\Users\\Papo\\AppData\\Roaming\\npm\\node_modules\\uglify-js\\bin\\uglifyjs"
But the same problem with ^^( caused error (screenshot below)
The plugin(?) is trying to escape the brackets.
(maybe it can decide if do escape based on presence of bat/cmd extension in uglifyjs_command)

So I did a PowerShell script, where I translated the contents of the uglify.cmd and
as PowerShell doesn't have a problem with (), I removed the ^^ from all arguments.
I than added:
"uglifyjs_command": "PowerShell.exe -ExecutionPolicy Unrestricted -File C:\Users\Papo\AppData\Roaming\npm\uglifyjs.ps1"

and now I can minimize/un-minimize files with () in their names.
also, I can use * (I haven't tested comments_to_keep with * yet, but * shows in a log file)

there is one weirdness though, the single ^ from: "comments_to_keep": "/^(?!XXX).*$/", is missing.
log doesn't show it, so it probably gets removed before the ps1 script


echo "args before:`n$args" | Out-File c:\_test\uglifyjs.log

for ($i=0; $i -lt $args.Length; $i++) {
    $args[$i] = $args[$i].Replace("^^","")
}

echo "`nargs after:`n$args" | Out-File c:\_test\uglifyjs.log -Append

if (Test-Path -LiteralPath $PSScriptRoot\node.exe) {
    &$PSScriptRoot\node.exe "$PSScriptRoot\node_modules\uglify-js\bin\uglifyjs" $args
} else {
    $env:PATHEXT = $env:PATHEXT.Replace(".js","")
    $env:PATHEXT = $env:PATHEXT.Replace(";;",";")
    &node "$PSScriptRoot\node_modules\uglify-js\bin\uglifyjs" $args
}

screenshot

@greyskin
Copy link

I'm having this issue (or related) in Sublime Text 3.

capture

@tssajo
Copy link
Owner

tssajo commented Mar 16, 2019

Guys, I feel your pain! I also use Windows myself and it is really tough to properly escape some commands and/or command arguments.

The Minify plugin for SublimeText is a multi platform plugin. It must work not only in Windows, but in OS X and Linux, too. What also complicate things is Python. All SublimeText plugin must be written in Python as far as I know and how Python deals with command line arguments and their escaping on various platforms is pretty much unpredictable, IMHO.

But if someone can come up with a good, multi platform safe solution to this escaping issue and submits a Pull request then I am not against merging that and then testing that.

Other then that, I must say that it is probably easier to rename those files which have spacial characters such as brackets in their file name. Don't you think? (E.g. Total Commander can do multi file renames.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants