From a2da9b6c02030293f3a412d16df819868c581a29 Mon Sep 17 00:00:00 2001 From: Matt Weidner Date: Sat, 22 Jul 2017 12:30:15 -0500 Subject: [PATCH] Added os.path.expanduser() before open() calls with user supplied paths --- mitmproxy/optmanager.py | 1 + pathod/language/generators.py | 2 +- pathod/pathoc_cmdline.py | 1 + pathod/pathod_cmdline.py | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py index e1d74b8e0..c28ec685f 100644 --- a/mitmproxy/optmanager.py +++ b/mitmproxy/optmanager.py @@ -518,6 +518,7 @@ def save(opts, path, defaults=False): Raises OptionsError if the existing data is corrupt. """ + path = os.path.expanduser(path) if os.path.exists(path) and os.path.isfile(path): with open(path, "rt", encoding="utf8") as f: try: diff --git a/pathod/language/generators.py b/pathod/language/generators.py index 1961df74d..70c6ad164 100644 --- a/pathod/language/generators.py +++ b/pathod/language/generators.py @@ -75,7 +75,7 @@ class RandomGenerator: class FileGenerator: def __init__(self, path): - self.path = path + self.path = os.path.expanduser(path) def __len__(self): return os.path.getsize(self.path) diff --git a/pathod/pathoc_cmdline.py b/pathod/pathoc_cmdline.py index 3b738d47a..0854f6ad9 100644 --- a/pathod/pathoc_cmdline.py +++ b/pathod/pathoc_cmdline.py @@ -208,6 +208,7 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr): reqs = [] for r in args.requests: + r = os.path.expanduser(r) if os.path.isfile(r): with open(r) as f: r = f.read() diff --git a/pathod/pathod_cmdline.py b/pathod/pathod_cmdline.py index dee19f4fc..c646aaeef 100644 --- a/pathod/pathod_cmdline.py +++ b/pathod/pathod_cmdline.py @@ -215,6 +215,7 @@ def args_pathod(argv, stdout_=sys.stdout, stderr_=sys.stderr): anchors = [] for patt, spec in args.anchors: + spec = os.path.expanduser(spec) if os.path.isfile(spec): with open(spec) as f: data = f.read()