Some more doc examples

Also disallow fragments that start with -
This commit is contained in:
Kovid Goyal
2024-05-22 08:40:01 +05:30
parent 83380cc916
commit f2a14a083b
3 changed files with 15 additions and 3 deletions

View File

@@ -31,12 +31,12 @@ following contents:
# by the hyperlink-grep kitten and nothing else so far.
protocol file
fragment_matches [0-9]+
action launch --type=overlay --cwd=current vim +${FRAGMENT} ${FILE_PATH}
action launch --type=overlay --cwd=current vim +${FRAGMENT} -- ${FILE_PATH}
# Open text files without fragments in the editor
protocol file
mime text/*
action launch --type=overlay --cwd=current ${EDITOR} ${FILE_PATH}
action launch --type=overlay --cwd=current -- ${EDITOR} -- ${FILE_PATH}
Now, run a search with::

View File

@@ -164,9 +164,16 @@ def actions_for_url_from_list(url: str, actions: Iterable[OpenAction]) -> Iterat
return
path = unquote(purl.path)
up = purl.path
frag = ''
if purl.query:
up += f'?{purl.query}'
if purl.fragment:
frag = unquote(purl.fragment)
if frag.startswith('-'):
# Dont allow fragments that startwith - as that can lead to arg
# injection
log_error('Ignoring fragment that starts with - in URL:', url)
frag = ''
up += f'#{purl.fragment}'
env = {
@@ -174,7 +181,7 @@ def actions_for_url_from_list(url: str, actions: Iterable[OpenAction]) -> Iterat
'FILE_PATH': path,
'URL_PATH': up,
'FILE': posixpath.basename(path),
'FRAGMENT': unquote(purl.fragment)
'FRAGMENT': frag,
}
def expand(x: Any) -> Any:

View File

@@ -1073,6 +1073,11 @@ 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(