diff --git a/docs/open_actions.rst b/docs/open_actions.rst index f64c73bb5..9e5f90b1f 100644 --- a/docs/open_actions.rst +++ b/docs/open_actions.rst @@ -64,6 +64,9 @@ some special variables, documented below: ``FRAGMENT`` The fragment (unquoted), if any of the URL or the empty string. +``NETLOC`` + The net location aka hostname (unquoted), if any of the URL or the empty string. + ``URL_PATH`` The path, query and fragment portions of the URL, without any unquoting. diff --git a/kitty/open_actions.py b/kitty/open_actions.py index 94d957456..409058bfb 100644 --- a/kitty/open_actions.py +++ b/kitty/open_actions.py @@ -69,7 +69,7 @@ def parse(lines: Iterable[str]) -> Iterator[OpenAction]: entries.append((tuple(match_criteria), tuple(raw_actions))) with to_cmdline_implementation.filter_env_vars( - 'URL', 'FILE_PATH', 'FILE', 'FRAGMENT', 'URL_PATH', + 'URL', 'FILE_PATH', 'FILE', 'FRAGMENT', 'URL_PATH', 'NETLOC', EDITOR=shlex.join(get_editor()), SHELL=resolved_shell(get_options())[0] ): @@ -164,6 +164,7 @@ def actions_for_url_from_list(url: str, actions: Iterable[OpenAction]) -> Iterat return path = unquote(purl.path) up = purl.path + netloc = unquote(purl.netloc) if purl.netloc else '' frag = '' if purl.query: up += f'?{purl.query}' @@ -181,6 +182,7 @@ def actions_for_url_from_list(url: str, actions: Iterable[OpenAction]) -> Iterat 'URL_PATH': up, 'FILE': posixpath.basename(path), 'FRAGMENT': frag, + 'NETLOC': netloc, } def expand(x: Any) -> Any: @@ -236,7 +238,7 @@ def default_open_actions() -> Tuple[OpenAction, ...]: # Open kitty HTML docs links protocol kitty+doc action show_kitty_doc $URL_PATH - '''.splitlines())) +'''.splitlines())) @run_once diff --git a/kitty/window.py b/kitty/window.py index 54ca93994..9f8c89e22 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -1073,11 +1073,6 @@ class Window: self.handle_remote_file(purl.netloc, unquote(purl.path)) return url = urlunparse(purl._replace(netloc='')) - if purl.fragment and purl.fragment.startswith('-'): - # Dont allow fragments that startwith - as that can lead to arg - # injection - log_error('Ignoring fragment that starts with - in URL:', url) - url = urlunparse(purl._replace(fragment='')) if opts.allow_hyperlinks & 0b10: from kittens.tui.operations import styled boss.choose(