From 2ea1f061ea0cfc43ca807a36b4d4616f5d4c8c69 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Fri, 15 Mar 2013 20:53:24 -0400 Subject: [PATCH] Stop auto-correcting incorrect slashes. Instead error, and point to our docs. Also, improve docs slightly to say to *always* use forward slashes See #906 --- docs/config.rst | 11 +++++- overviewer_core/settingsValidators.py | 52 +++++++++++++-------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index e603ca7..9994fd3 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -10,10 +10,15 @@ like this:: overviewer.py --config=path/to/my_configfile - The config file is formatted in Python syntax. If you aren't familiar with Python, don't worry, it's pretty simple. Just follow the examples. +.. note:: + + You should *always* use forward slashes ("/"), even on + Windows. This is required because the backslash ("\\") has special meaning + in Python. + A Simple Example ================ @@ -193,6 +198,8 @@ the form ``key = value``. Two items take a different form:, ``worlds`` and **You must specify at least one world** + *Reminder*: Always use forward slashes ("/"), even on Windows. + ``renders`` This is also pre-defined as an empty dictionary. The config file is expected to add at least one item to it. @@ -226,6 +233,8 @@ the form ``key = value``. Two items take a different form:, ``worlds`` and outputdir = "/path/to/output" + *Reminder*: Always use forward slashes ("/"), even on Windows. + **Required** .. _processes: diff --git a/overviewer_core/settingsValidators.py b/overviewer_core/settingsValidators.py index 6d49da8..6b5afa9 100644 --- a/overviewer_core/settingsValidators.py +++ b/overviewer_core/settingsValidators.py @@ -24,30 +24,26 @@ def expand_path(p): return p def checkBadEscape(s): - fixed = False - fixed_string = s - if "\a" in fixed_string: - fixed_string = s.replace("\a", r"\a") - fixed = True - if "\b" in fixed_string: - fixed_string = s.replace("\b", r"\b") - fixed = True - if "\t" in fixed_string: - fixed_string = s.replace("\t", r"\t") - fixed = True - if "\n" in fixed_string: - fixed_string = s.replace("\n", r"\n") - fixed = True - if "\v" in fixed_string: - fixed_string = s.replace("\v", r"\v") - fixed = True - if "\f" in fixed_string: - fixed_string = s.replace("\f", r"\f") - fixed = True - if "\r" in fixed_string: - fixed_string = s.replace("\r", r"\r") - fixed = True - return (fixed, fixed_string) + #If any of these weird characters are in the path, raise an exception instead of fixing + #this should help us educate our users about pathslashes + if "\a" in s: + raise ValueError("Invalid character '\\a' in path. Please use forward slashes ('/'). Please see our docs for more info.") + if "\b" in s: + raise ValueError("Invalid character '\\b' in path. Please use forward slashes ('/'). Please see our docs for more info.") + if "\t" in s: + raise ValueError("Invalid character '\\t' in path. Please use forward slashes ('/'). Please see our docs for more info.") + if "\n" in s: + raise ValueError("Invalid character '\\n' in path. Please use forward slashes ('/'). Please see our docs for more info.") + if "\v" in s: + raise ValueError("Invalid character '\\v' in path. Please use forward slashes ('/'). Please see our docs for more info.") + if "\f" in s: + raise ValueError("Invalid character '\\f' in path. Please use forward slashes ('/'). Please see our docs for more info.") + if "\r" in s: + raise ValueError("Invalid character '\\r' in path. Please use forward slashes ('/'). Please see our docs for more info.") + for c in range(10): + if chr(c) in s: + raise ValueError("Invalid character '\\%s' in path. Please use forward slashes ('/'). Please see our docs for more info." % c) + return s def validateMarkers(filterlist): if type(filterlist) != list: @@ -72,7 +68,7 @@ def validateOverlays(renderlist): return renderlist def validateWorldPath(worldpath): - _, worldpath = checkBadEscape(worldpath) + checkBadEscape(worldpath) abs_path = expand_path(worldpath) if not os.path.exists(os.path.join(abs_path, "level.dat")): raise ValidationException("No level.dat file in '%s'. Are you sure you have the right path?" % (abs_path,)) @@ -199,7 +195,7 @@ def validateDimension(d): return (d, d) def validateOutputDir(d): - _, d = checkBadEscape(d) + checkBadEscape(d) if not d.strip(): raise ValidationException("You must specify a valid output directory") return expand_path(d) @@ -234,8 +230,8 @@ def validateWebAssetsPath(p): raise ValidationException("Bad custom web assets path: %s" % e.message) def validatePath(p): - _, path = checkBadEscape(p) - abs_path = expand_path(path) + checkBadEscape(p) + abs_path = expand_path(p) if not os.path.exists(abs_path): raise ValidationException("'%s' does not exist. Path initially given as '%s'" % (abs_path,p))