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

Script crashes when located in a path containing special characters #53

Open
ScriptTiger opened this issue May 23, 2020 · 5 comments
Open
Assignees
Labels

Comments

@ScriptTiger
Copy link
Owner

ScriptTiger commented May 23, 2020

Just received the following issue:

For a long time I was using the hosts script regularly without issue. Then about 2 months ago I started getting the following error. Using on windows 10 with all updates, script version 1.43.

C:\Program Files (x86)\Unified-Hosts-AutoUpdate-master>hosts_update.cmd
Initializing...
\Unified-Hosts-AutoUpdate-master\log.txt was unexpected at this time.

This is due to the script's path containing parentheses, (x86).

EDIT: @fusionneur also reported issues with exclamation points.

@ScriptTiger ScriptTiger self-assigned this May 23, 2020
@Uj947nXmRqV2nRaWshKtHzTvckUUpD

i saw some weird behavior when path contains ! as well

@ScriptTiger ScriptTiger changed the title Script crashes when located in a path containing parentheses Script crashes when located in a path containing special characters Dec 19, 2020
@ScriptTiger
Copy link
Owner Author

Thanks! I renamed the issue and added your observation to my initial post. I'm not sure when I'll be able to get back to this project, but these will definitely be the first things on the to-do list.

@matheger
Copy link

matheger commented Feb 3, 2022

Fixed the problem.

On line 30:
set set SELF=%~f0
Enclose the %~f0 in double quotes.

On line 98:
set LOG=%LOGD%
Replace the percent signs with exclamation points: !LOGD!

@ScriptTiger
Copy link
Owner Author

@matheger, thanks for working on this!

As both SELF and LOG are only used for logging purposes, it doesn't appear as though your fixes actually change the script's primary functionality. Can you confirm other things that require the full script path, like script updates, task scheduling, custom/ignore, etc., are all fixed by your changes? Deleting any current task you have, removing the Unified Hosts from your hosts file, and installing the script from the beginning would be a good test for this. Making sure paths with spaces work is also required, as well, since that is much more common than paths with special characters.

I am definitely game to entertain a PR if you can fix the logging while simultaneously fix all the other full path references without throwing the baby out with the bathwater. The current implementation is just a compromise to get the script to work for the most people in the safest possible way, while still failing safely for those it doesn't work for.

@matheger
Copy link

matheger commented Feb 4, 2022

I figured that it was only related to logging, and due to some sort of string escaping, which seemed really unfortunate that it broke the whole thing. With those fixes I've been running it from the command line without problem, and task scheduler doesn't seem to have any issue with it either. I can give it some more testing in the next few days. (I've rarely ever touched batch scripts so whatever I come up with might be wonky.)

btw, I've been running it in C:\Progam Files (x86) so parentheses and whitespaces seem to work.

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

No branches or pull requests

3 participants