Handle user variables in path correctly
This commit is contained in:
parent
1a73a90515
commit
400f619903
1
doc/TODO
1
doc/TODO
@ -50,7 +50,6 @@ Downloads
|
|||||||
Improvements / minor features
|
Improvements / minor features
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
- qutebrowser local_file.foo should open that file in $PWD
|
|
||||||
- Distinction between :q and :wq, add ZZ and ZQ shortcuts.
|
- Distinction between :q and :wq, add ZZ and ZQ shortcuts.
|
||||||
- set_toggle to toggle setting between two states
|
- set_toggle to toggle setting between two states
|
||||||
- Customizable statusbar
|
- Customizable statusbar
|
||||||
|
@ -209,7 +209,7 @@ class DownloadItem(QObject):
|
|||||||
None: special value to stop the download.
|
None: special value to stop the download.
|
||||||
"""
|
"""
|
||||||
if os.path.isabs(filename):
|
if os.path.isabs(filename):
|
||||||
target = filename
|
target = os.path.expanduser(filename)
|
||||||
else:
|
else:
|
||||||
download_dir = config.get('storage', 'download-directory')
|
download_dir = config.get('storage', 'download-directory')
|
||||||
target = os.path.join(download_dir, filename)
|
target = os.path.join(download_dir, filename)
|
||||||
|
@ -580,10 +580,16 @@ class File(BaseType):
|
|||||||
typestr = 'file'
|
typestr = 'file'
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
|
value = os.path.expanduser(value)
|
||||||
if self.none_ok and not value:
|
if self.none_ok and not value:
|
||||||
return
|
return
|
||||||
if not os.path.isfile(value):
|
if not os.path.isfile(value):
|
||||||
raise ValidationError(value, "must be a valid file!")
|
raise ValidationError(value, "must be a valid file!")
|
||||||
|
if not os.path.isabs(value):
|
||||||
|
raise ValidationError(value, "must be an absolute path!")
|
||||||
|
|
||||||
|
def transform(self, value):
|
||||||
|
return os.path.expanduser(value)
|
||||||
|
|
||||||
|
|
||||||
class Directory(BaseType):
|
class Directory(BaseType):
|
||||||
@ -597,11 +603,13 @@ class Directory(BaseType):
|
|||||||
return
|
return
|
||||||
if not os.path.isdir(value):
|
if not os.path.isdir(value):
|
||||||
raise ValidationError(value, "must be a valid directory!")
|
raise ValidationError(value, "must be a valid directory!")
|
||||||
|
if not os.path.isabs(value):
|
||||||
|
raise ValidationError(value, "must be an absolute path!")
|
||||||
|
|
||||||
def transform(self, value):
|
def transform(self, value):
|
||||||
if not value:
|
if not value:
|
||||||
return get_standard_dir(QStandardPaths.DownloadLocation)
|
return get_standard_dir(QStandardPaths.DownloadLocation)
|
||||||
return value
|
return os.path.expanduser(value)
|
||||||
|
|
||||||
|
|
||||||
class WebKitBytes(BaseType):
|
class WebKitBytes(BaseType):
|
||||||
|
@ -122,8 +122,12 @@ def fuzzy_url(urlstr):
|
|||||||
Return:
|
Return:
|
||||||
A target QUrl to a searchpage or the original URL.
|
A target QUrl to a searchpage or the original URL.
|
||||||
"""
|
"""
|
||||||
|
path = os.path.abspath(os.path.expanduser(urlstr))
|
||||||
stripped = urlstr.strip()
|
stripped = urlstr.strip()
|
||||||
if is_url(stripped):
|
if os.path.exists(path):
|
||||||
|
logger.debug("URL is a local file")
|
||||||
|
url = QUrl.fromLocalFile(path)
|
||||||
|
elif is_url(stripped):
|
||||||
# probably an address
|
# probably an address
|
||||||
logger.debug("URL is a fuzzy address")
|
logger.debug("URL is a fuzzy address")
|
||||||
url = QUrl.fromUserInput(urlstr)
|
url = QUrl.fromUserInput(urlstr)
|
||||||
@ -180,9 +184,6 @@ def is_url(urlstr):
|
|||||||
# Special URLs are always URLs, even with autosearch=False
|
# Special URLs are always URLs, even with autosearch=False
|
||||||
logger.debug("Is an special URL.")
|
logger.debug("Is an special URL.")
|
||||||
return True
|
return True
|
||||||
elif os.path.exists(urlstr):
|
|
||||||
# local file
|
|
||||||
return True
|
|
||||||
elif autosearch == 'dns':
|
elif autosearch == 'dns':
|
||||||
logger.debug("Checking via DNS")
|
logger.debug("Checking via DNS")
|
||||||
# We want to use fromUserInput here, as the user might enter "foo.de"
|
# We want to use fromUserInput here, as the user might enter "foo.de"
|
||||||
|
Loading…
Reference in New Issue
Block a user