Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

webbrowser.register incorrectly prefers wrong browser if its name is a substring ofxdg-settings get default-web-browser result #108172

Closed
Labels
stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@guss77

Description

@guss77

Bug report

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched theCPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.11.4 (main, Jun 9 2023, 07:59:55) [GCC 12.3.0]

A clear and concise description of the bug:

I'm using a custom desktop entry (Linux application launcher) that starts Google Chrome with my custom data dir (or any other setting that is relevant). The custom desktop entry is calledgoogle-chrome-work.desktop (I have a few other Google Chrome custom launchers for other cases where I need the data dir separated), and this is set as the default browser in the operating system:

$ xdg-settings get default-web-browsergoogle-chrome-work.desktop

When using thewebbrowser to open a URL, without first registering any specific browser, it callsregister_standard_browsers() and that in turn runsxdg-settings get default-web-browser, and if that succeeds - sets up the resulting string (which is expected to be a.desktop entry) in_os_preferred_browser. After thatregister_X_browsers() gets run which knows about a bunch of browsers one might expect to find on Unix systems and tries to register each found with a call toregister(). The first such "browser" to be registered isxdg-open - which will automatically use the system preferred web browser (using the XDG spec, that was consulted earlier), and one can always expect to find whenxdg-settings is available (both are part of the same spec and always come from the same software package).

All this is great. The problem is thatregister() wants to check if the registered browser is supposedly the_os_preferred_browser and uses sub string comparison to check that:name in _os_preferred_browser. In my case - because the text "google-chrome" (which is a browser name thatregister_X_browsers() knows) is a substring ofgoogle-chrome-work.desktop - it chooses to have the bare command for Google Chrome as the preferred browser, even though this is definitely not what is needed.

I've looked at the code, and_os_preferred_browser isonly used to handle the result ofxdg-settings get default-web-browser, so this substring search makes no sense - if_os_preferred_browser is set and has a value - it is guaranteed that usingxdg-open is the correct command - we have basically verified that we have a valid FreeDesktop.org default browser configuration so using it is the only thing that is compatible with the FreeDesktop.org specifications (theoretically, we should execute the desktop entry file directly, but that is a lot more complicated and callingxdg-open with an HTTP URL will do the Right Thing™️).

This issue should be fixed by:

  1. Removing the substring search - it makes no sense.
  2. Make sure to register "xdg-open" (here) in a way that is set as the preferred browser if_os_preferred_browser is set, for example:
ifshutil.which("xdg-open"):register("xdg-open",None,BackgroundBrowser("xdg-open"),_os_preferred_browserisnotNone)

I can offer a PR if this seems reasonable.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp