Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-128540: Fixed webbrowser.open with file: URLs may launching editor instead of browser #130031

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ def register_standard_browsers():
class WindowsDefault(BaseBrowser):
def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
if url.startswith("file:"):
return False
try:
os.startfile(url)
except OSError:
Expand All @@ -595,6 +597,8 @@ def __init__(self, name='default'):

def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
if url.startswith("file:"):
return False
url = url.replace('"', '%22')
if self.name == 'default':
script = f'open location "{url}"' # opens in default browser
Expand Down Expand Up @@ -626,6 +630,8 @@ def open(self, url, new=0, autoraise=True):
class IOSBrowser(BaseBrowser):
def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
if url.startswith("file:"):
return False
# If ctypes isn't available, we can't open a browser
if objc is None:
return False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed :func:`webbrowser.open` with ``file:`` URLs may launching editor
instead of browser
Loading