From b4d9f1f5e5467bb2469e870e7d9afb2cbcfb491c Mon Sep 17 00:00:00 2001 From: invis-z <22781620+invis-z@users.noreply.github.com> Date: Thu, 28 Apr 2022 04:25:14 +0800 Subject: [PATCH] Remove "/" before endpoints & tags (#734) Removes the leading slash before imgres and other endpoints Fix #733 --- app/filter.py | 7 ++++--- app/utils/results.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/filter.py b/app/filter.py index 24ba8a0..7412275 100644 --- a/app/filter.py +++ b/app/filter.py @@ -72,7 +72,7 @@ def clean_css(css: str, page_url: str) -> str: continue css = css.replace( url, - f'/element?type=image/png&url={abs_url}' + f'{Endpoint.element}?type=image/png&url={abs_url}' ) return css @@ -466,7 +466,8 @@ class Filter: if href.startswith(MAPS_URL): # Maps links don't work if a site filter is applied link['href'] = MAPS_URL + "?q=" + clean_query(q) - elif href.startswith('/?') or href.startswith('/search?'): + elif (href.startswith('/?') or href.startswith('/search?') or + href.startswith('/imgres?')): # make sure that tags can be clicked as relative URLs link['href'] = href[1:] elif href.startswith('/intl/'): @@ -528,7 +529,7 @@ class Filter: continue img_url = urlparse.unquote(urls[0].replace( - f'/{Endpoint.imgres}?imgurl=', '')) + f'{Endpoint.imgres}?imgurl=', '')) try: # Try to strip out only the necessary part of the web page link diff --git a/app/utils/results.py b/app/utils/results.py index 2341c36..a2b8083 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -186,7 +186,7 @@ def append_nojs(result: BeautifulSoup) -> None: """ nojs_link = BeautifulSoup(features='html.parser').new_tag('a') - nojs_link['href'] = f'/{Endpoint.window}?nojs=1&location=' + result['href'] + nojs_link['href'] = f'{Endpoint.window}?nojs=1&location=' + result['href'] nojs_link.string = ' NoJS Link' result.append(nojs_link) @@ -206,7 +206,7 @@ def append_anon_view(result: BeautifulSoup, config: Config) -> None: av_link = BeautifulSoup(features='html.parser').new_tag('a') nojs = 'nojs=1' if config.nojs else 'nojs=0' location = f'location={result["href"]}' - av_link['href'] = f'/{Endpoint.window}?{nojs}&{location}' + av_link['href'] = f'{Endpoint.window}?{nojs}&{location}' translation = current_app.config['TRANSLATIONS'][ config.get_localization_lang() ]