python / python/cpython

webbrowser has no escape for os.pathsep

未關閉
#133,138 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

aws-sso-util uses the browser module to open the AWS Identity Center login flow.

Sometimes I need to open the login flow in Firefox using a specific container.

The only way I know to open a specific container in Firefox is to use the open-url-in-container extension. It provides a custom protocol handler to follow a URL in a specific container.

So to open the Identity Center start URL in container ABC123, I'd set the BROWSER variable like this before invoking aws-sso-util login:

export BROWSER="firefox ext+container:name=ABC123&url=%s"

But it doesn't work. Instead aws-sso-util prints an error:

Login failed: Failed to open browser

webbrowser.open_new_tab raises an exception to make it print this. (source code).

The problem seems to be the : character in the protocol handler. The doc says the module handles that as list separator.

If the environment variable BROWSER exists, it is interpreted as the os.pathsep-separated list of browsers to try ahead of the platform defaults. When the value of a list part contains the string %s, then it is interpreted as a literal browser command line to be used with the argument URL substituted for %s; if the part does not contain %s, it is simply interpreted as the name of the browser to launch. [1]

The doc doesn't show any way to escape the :. I've tried \: and :: without any change in behavior.

I also tried URL escaping. This launches the browser, but opens the wrong thing because it no longer recognizes the custom protocol handler.

export BROWSER="firefox ext+container%3Aname=ABC123&url=%s"

Firefox can’t find the file at /project/ext container:name=ABC123&url=https://d-....awsapps.com/start/#/device?user_code=....

CPython versions tested on:

3.10

Operating systems tested on:

No response

Linked PRs
  • gh-152474

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 webbrowser 文件和 webbrowser.open_new_tab 進入點開始;重現自訂通訊協定處理常式顯示的 BROWSER 值。檢視相關工作 gh-152474 和回報中的 aws_sso_lib/browser.py 呼叫位置,然後驗證包含 os.pathsep 的瀏覽器命令可以在不被錯誤拆分的情況下傳入。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
tooling
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。