Script crashes when located in a path containing special characters
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.
i saw some weird behavior when path contains ! as well
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.
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!
@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.
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.