]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-108172: do not override OS preferred browser if it is a super-string of a known...
authorOded Arbel <oded@geek.co.il>
Sat, 31 Aug 2024 06:11:57 +0000 (09:11 +0300)
committerGitHub <noreply@github.com>
Sat, 31 Aug 2024 06:11:57 +0000 (23:11 -0700)
When checking if the registering browser is the "OS preferred browser", do not use a substring search - that makes no sense: one can have a preferred browser that looks like a super-string of a known browser, e.g. "firefox-nightly" vs "firefox".

https://github.com/python/cpython/issues/108172 explains in more detail, and lays out a potential better future enhancement for this case of just using xdg-open.  We'll go with this for now.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Lib/webbrowser.py
Misc/NEWS.d/next/Library/2023-12-12-15-19-58.gh-issue-108172.KyDPuG.rst [new file with mode: 0644]

index 6fca257c02664f545055b19ecac7f85ac9db2297..252ca92337e272696c8d9928ecbbb3521fb09ec4 100644 (file)
@@ -31,7 +31,7 @@ def register(name, klass, instance=None, *, preferred=False):
         # Preferred browsers go to the front of the list.
         # Need to match to the default browser returned by xdg-settings, which
         # may be of the form e.g. "firefox.desktop".
-        if preferred or (_os_preferred_browser and name in _os_preferred_browser):
+        if preferred or (_os_preferred_browser and f'{name}.desktop' == _os_preferred_browser):
             _tryorder.insert(0, name)
         else:
             _tryorder.append(name)
diff --git a/Misc/NEWS.d/next/Library/2023-12-12-15-19-58.gh-issue-108172.KyDPuG.rst b/Misc/NEWS.d/next/Library/2023-12-12-15-19-58.gh-issue-108172.KyDPuG.rst
new file mode 100644 (file)
index 0000000..5c6b9cd
--- /dev/null
@@ -0,0 +1 @@
+``webbrowser`` honors OS preferred browser on Linux when its desktop entry name contains the text of a known browser name.