Skip to content

Commit

Permalink
bpo-35308: Fix regression where BROWSER env var is not respected. (GH…
Browse files Browse the repository at this point in the history
…-10693)

Regression introduced in e3ce695 and 25b804a, where the old parameter
update_tryorder to _synthesize was first ignored, then given the opposite
value in the attempt to fix bpo-31014.
  • Loading branch information
zmwangx authored and serhiy-storchaka committed Nov 26, 2018
1 parent 5a8c240 commit 8c281ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Lib/test/test_webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,24 @@ def test_environment(self):
webbrowser = support.import_fresh_module('webbrowser')
webbrowser.get()

def test_environment_preferred(self):
webbrowser = support.import_fresh_module('webbrowser')
try:
webbrowser.get()
least_preferred_browser = webbrowser.get(webbrowser._tryorder[-1]).name
except (webbrowser.Error, AttributeError, IndexError) as err:
self.skipTest(str(err))

with support.EnvironmentVarGuard() as env:
env["BROWSER"] = least_preferred_browser
webbrowser = support.import_fresh_module('webbrowser')
self.assertEqual(webbrowser.get().name, least_preferred_browser)

with support.EnvironmentVarGuard() as env:
env["BROWSER"] = sys.executable
webbrowser = support.import_fresh_module('webbrowser')
self.assertEqual(webbrowser.get().name, sys.executable)


if __name__=='__main__':
unittest.main()
4 changes: 2 additions & 2 deletions Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def open_new_tab(url):
return open(url, 2)


def _synthesize(browser, *, preferred=True):
def _synthesize(browser, *, preferred=False):
"""Attempt to synthesize a controller base on existing controllers.
This is useful to create a controller when a user specifies a path to
Expand Down Expand Up @@ -563,7 +563,7 @@ def register_standard_browsers():
# and prepend to _tryorder
for cmdline in userchoices:
if cmdline != '':
cmd = _synthesize(cmdline, preferred=False)
cmd = _synthesize(cmdline, preferred=True)
if cmd[1] is None:
register(cmdline, None, GenericBrowser(cmdline), preferred=True)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix regression in ``webbrowser`` where default browsers may be preferred
over browsers in the ``BROWSER`` environment variable.

0 comments on commit 8c281ed

Please sign in to comment.