Handle user variables in path correctly

This commit is contained in:
Florian Bruhin 2014-06-28 01:15:31 +02:00
parent 1a73a90515
commit 400f619903
4 changed files with 15 additions and 7 deletions

View File

@ -50,7 +50,6 @@ Downloads
Improvements / minor features
=============================
- qutebrowser local_file.foo should open that file in $PWD
- Distinction between :q and :wq, add ZZ and ZQ shortcuts.
- set_toggle to toggle setting between two states
- Customizable statusbar

View File

@ -209,7 +209,7 @@ class DownloadItem(QObject):
None: special value to stop the download.
"""
if os.path.isabs(filename):
target = filename
target = os.path.expanduser(filename)
else:
download_dir = config.get('storage', 'download-directory')
target = os.path.join(download_dir, filename)

View File

@ -580,10 +580,16 @@ class File(BaseType):
typestr = 'file'
def validate(self, value):
value = os.path.expanduser(value)
if self.none_ok and not value:
return
if not os.path.isfile(value):
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):
@ -597,11 +603,13 @@ class Directory(BaseType):
return
if not os.path.isdir(value):
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):
if not value:
return get_standard_dir(QStandardPaths.DownloadLocation)
return value
return os.path.expanduser(value)
class WebKitBytes(BaseType):

View File

@ -122,8 +122,12 @@ def fuzzy_url(urlstr):
Return:
A target QUrl to a searchpage or the original URL.
"""
path = os.path.abspath(os.path.expanduser(urlstr))
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
logger.debug("URL is a fuzzy address")
url = QUrl.fromUserInput(urlstr)
@ -180,9 +184,6 @@ def is_url(urlstr):
# Special URLs are always URLs, even with autosearch=False
logger.debug("Is an special URL.")
return True
elif os.path.exists(urlstr):
# local file
return True
elif autosearch == 'dns':
logger.debug("Checking via DNS")
# We want to use fromUserInput here, as the user might enter "foo.de"