Merge branch 'forkbong-pretty_url_2'
This commit is contained in:
commit
0277c47ffa
@ -22,6 +22,7 @@ Added
|
|||||||
|
|
||||||
- New `:edit-url` command to edit the URL in an external editor.
|
- New `:edit-url` command to edit the URL in an external editor.
|
||||||
- New `network -> custom-headers` setting to send custom headers with every request.
|
- New `network -> custom-headers` setting to send custom headers with every request.
|
||||||
|
- New `{url:pretty}` commandline replacement which gets replaced by the decoded URL.
|
||||||
|
|
||||||
Changed
|
Changed
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
@ -173,10 +173,10 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* John ShaggyTwoDope Jenkins
|
* John ShaggyTwoDope Jenkins
|
||||||
* Jimmy
|
* Jimmy
|
||||||
* Peter Vilim
|
* Peter Vilim
|
||||||
|
* Panagiotis Ktistakis
|
||||||
* Clayton Craft
|
* Clayton Craft
|
||||||
* Oliver Caldwell
|
* Oliver Caldwell
|
||||||
* Jonas Schürmann
|
* Jonas Schürmann
|
||||||
* Panagiotis Ktistakis
|
|
||||||
* Jakub Klinkovský
|
* Jakub Klinkovský
|
||||||
* skinnay
|
* skinnay
|
||||||
* error800
|
* error800
|
||||||
|
@ -655,7 +655,7 @@ Syntax: +:spawn [*--userscript*] [*--verbose*] [*--detach*] 'cmdline'+
|
|||||||
|
|
||||||
Spawn a command in a shell.
|
Spawn a command in a shell.
|
||||||
|
|
||||||
Note the {url} variable which gets replaced by the current URL might be useful here.
|
Note the `{url}` and `{url:pretty}` variables might be useful here. `{url}` gets replaced by the URL in fully encoded format and `{url:pretty}` uses a "pretty form" with most percent-encoded characters decoded.
|
||||||
|
|
||||||
==== positional arguments
|
==== positional arguments
|
||||||
* +'cmdline'+: The commandline to execute.
|
* +'cmdline'+: The commandline to execute.
|
||||||
|
@ -974,8 +974,10 @@ class CommandDispatcher:
|
|||||||
def spawn(self, cmdline, userscript=False, verbose=False, detach=False):
|
def spawn(self, cmdline, userscript=False, verbose=False, detach=False):
|
||||||
"""Spawn a command in a shell.
|
"""Spawn a command in a shell.
|
||||||
|
|
||||||
Note the {url} variable which gets replaced by the current URL might be
|
Note the `{url}` and `{url:pretty}` variables might be useful here.
|
||||||
useful here.
|
`{url}` gets replaced by the URL in fully encoded format and
|
||||||
|
`{url:pretty}` uses a "pretty form" with most percent-encoded
|
||||||
|
characters decoded.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
userscript: Run the command as a userscript. You can use an
|
userscript: Run the command as a userscript. You can use an
|
||||||
|
@ -33,24 +33,33 @@ ParseResult = collections.namedtuple('ParseResult', ['cmd', 'args', 'cmdline',
|
|||||||
'count'])
|
'count'])
|
||||||
|
|
||||||
|
|
||||||
def replace_variables(win_id, arglist):
|
def _current_url(tabbed_browser):
|
||||||
"""Utility function to replace variables like {url} in a list of args."""
|
"""Convenience method to get the current url."""
|
||||||
args = []
|
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
|
||||||
window=win_id)
|
|
||||||
if '{url}' in arglist:
|
|
||||||
try:
|
try:
|
||||||
url = tabbed_browser.current_url().toString(QUrl.FullyEncoded |
|
return tabbed_browser.current_url()
|
||||||
QUrl.RemovePassword)
|
|
||||||
except qtutils.QtValueError as e:
|
except qtutils.QtValueError as e:
|
||||||
msg = "Current URL is invalid"
|
msg = "Current URL is invalid"
|
||||||
if e.reason:
|
if e.reason:
|
||||||
msg += " ({})".format(e.reason)
|
msg += " ({})".format(e.reason)
|
||||||
msg += "!"
|
msg += "!"
|
||||||
raise cmdexc.CommandError(msg)
|
raise cmdexc.CommandError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def replace_variables(win_id, arglist):
|
||||||
|
"""Utility function to replace variables like {url} in a list of args."""
|
||||||
|
args = []
|
||||||
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
|
window=win_id)
|
||||||
|
if '{url}' in arglist:
|
||||||
|
url = _current_url(tabbed_browser).toString(QUrl.FullyEncoded |
|
||||||
|
QUrl.RemovePassword)
|
||||||
|
if '{url:pretty}' in arglist:
|
||||||
|
pretty_url = _current_url(tabbed_browser).toString(QUrl.RemovePassword)
|
||||||
for arg in arglist:
|
for arg in arglist:
|
||||||
if arg == '{url}':
|
if arg == '{url}':
|
||||||
args.append(url)
|
args.append(url)
|
||||||
|
elif arg == '{url:pretty}':
|
||||||
|
args.append(pretty_url)
|
||||||
else:
|
else:
|
||||||
args.append(arg)
|
args.append(arg)
|
||||||
return args
|
return args
|
||||||
|
10
tests/integration/data/title with spaces.html
Normal file
10
tests/integration/data/title with spaces.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
foo
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -276,10 +276,12 @@ def expect_message(quteproc, httpbin, category, message):
|
|||||||
|
|
||||||
@bdd.then(bdd.parsers.re(r'(?P<is_regex>regex )?"(?P<pattern>[^"]+)" should '
|
@bdd.then(bdd.parsers.re(r'(?P<is_regex>regex )?"(?P<pattern>[^"]+)" should '
|
||||||
r'be logged'))
|
r'be logged'))
|
||||||
def should_be_logged(quteproc, is_regex, pattern):
|
def should_be_logged(quteproc, httpbin, is_regex, pattern):
|
||||||
"""Expect the given pattern on regex in the log."""
|
"""Expect the given pattern on regex in the log."""
|
||||||
if is_regex:
|
if is_regex:
|
||||||
pattern = re.compile(pattern)
|
pattern = re.compile(pattern)
|
||||||
|
else:
|
||||||
|
pattern = pattern.replace('(port)', str(httpbin.port))
|
||||||
line = quteproc.wait_for(message=pattern)
|
line = quteproc.wait_for(message=pattern)
|
||||||
line.expected = True
|
line.expected = True
|
||||||
|
|
||||||
|
@ -16,9 +16,20 @@ Feature: :spawn
|
|||||||
When I run :spawn echo {url}
|
When I run :spawn echo {url}
|
||||||
Then "Executing echo with args ['about:blank'], userscript=False" should be logged
|
Then "Executing echo with args ['about:blank'], userscript=False" should be logged
|
||||||
|
|
||||||
|
Scenario: Running :spawn with url variable in fully encoded format
|
||||||
|
When I open data/title with spaces.html
|
||||||
|
And I run :spawn echo {url}
|
||||||
|
Then "Executing echo with args ['http://localhost:(port)/data/title%20with%20spaces.html'], userscript=False" should be logged
|
||||||
|
|
||||||
|
Scenario: Running :spawn with url variable in pretty decoded format
|
||||||
|
When I open data/title with spaces.html
|
||||||
|
And I run :spawn echo {url:pretty}
|
||||||
|
Then "Executing echo with args ['http://localhost:(port)/data/title with spaces.html'], userscript=False" should be logged
|
||||||
|
|
||||||
@posix
|
@posix
|
||||||
Scenario: Running :spawn with userscript
|
Scenario: Running :spawn with userscript
|
||||||
When I execute the userscript open_current_url
|
When I open about:blank
|
||||||
|
And I execute the userscript open_current_url
|
||||||
And I wait until about:blank is loaded
|
And I wait until about:blank is loaded
|
||||||
Then the following tabs should be open:
|
Then the following tabs should be open:
|
||||||
- about:blank
|
- about:blank
|
||||||
|
Loading…
Reference in New Issue
Block a user