normalize url path and strip trailing slashes when doing gu/gU, normalize every qute://* urls and raise OSError when a url redirects to a directory in qute://help/ pages

This commit is contained in:
dwagle 2017-11-14 21:02:54 +05:45
parent e72e8b8556
commit b3b768f4a8
4 changed files with 40 additions and 1 deletions

View File

@ -64,6 +64,7 @@ def path_up(url, count):
raise Error("Can't go up!")
for _i in range(0, min(count, path.count('/'))):
path = posixpath.join(path, posixpath.pardir)
path = posixpath.normpath(path)
url.setPath(path)
return url

View File

@ -135,6 +135,11 @@ def data_for_url(url):
Return:
A (mimetype, data) tuple.
"""
# normalize path and strip redundant trailing slashes
norm_url = url.adjusted(QUrl.NormalizePathSegments | QUrl.StripTrailingSlash)
if norm_url != url:
raise Redirect(norm_url)
path = url.path()
host = url.host()
query = urlutils.query_string(url)
@ -331,9 +336,13 @@ def qute_help(url):
path = 'html/doc/{}'.format(urlpath)
if not urlpath.endswith('.html'):
try:
bdata = utils.read_file(path, binary=True)
except OSError as e:
raise QuteSchemeOSError(e)
mimetype, _encoding = mimetypes.guess_type(urlpath)
assert mimetype is not None, url
return mimetype, utils.read_file(path, binary=True)
return mimetype, bdata
try:
data = utils.read_file(path)

View File

@ -18,6 +18,22 @@ Feature: Using :navigate
And I run :navigate up with count 2
Then data/navigate should be loaded
Scenario: Navigating up in qute://help/
When I open qute://help/commands.html
And I run :navigate up
Then qute://help/ should be loaded
Scenario: Navigating up by count in qute://help/
When I open qute://help/img/cheatsheet-big.png
And I run :navigate up with count 2
Then qute://help/ should be loaded
Scenario: Navigating up in qute://help/img/cheatsheet-big.png
When I open qute://help/img/cheatsheet-big.png
And I run :navigate up
Then "OSError while handling qute://* URL" should be logged
And "* url='qute://help/img'* LoadStatus.error" should be logged
# prev/next
Scenario: Navigating to previous page

View File

@ -63,6 +63,19 @@ Feature: Special qute:// pages
And I hint with args "links normal" and follow a
Then qute://help/quickstart.html should be loaded
Scenario: Opening a link with qute://help/index.html/..
When I open qute://help/index.html/.. without waiting
Then qute://help/ should be loaded
Scenario: Opening a link with qute://help/index.html/../
When I open qute://help/index.html/../ without waiting
Then qute://help/ should be loaded
Scenario: Opening a link with qute://help/img/cheatsheet-big.png/..
When I open qute://help/img/cheatsheet-big.png/.. without waiting
Then "OSError while handling qute://* URL" should be logged
And "* url='qute://help/img'* LoadStatus.error" should be logged
# :history
Scenario: :history without arguments