Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94dd7cb

Browse files
committed
#15509: If %action substitution produces a null string, drop it.
Patch by Anton Barkovsky, comment addition by me. This showed up as a bug in 3.3 because the definition for Chrome produced such an empty string. This fix is tested in 3.3+; backporting the new test suite is more trouble than it is worth.
1 parent c7dedb0 commit 94dd7cb

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Lib/webbrowser.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,18 @@ class UnixBrowser(BaseBrowser):
206206
"""Parent class for all Unix browsers with remote functionality."""
207207

208208
raise_opts = None
209+
background = False
210+
redirect_stdout = True
211+
# In remote_args, %s will be replaced with the requested URL. %action will
212+
# be replaced depending on the value of 'new' passed to open.
213+
# remote_action is used for new=0 (open). If newwin is not None, it is
214+
# used for new=1 (open_new). If newtab is not None, it is used for
215+
# new=3 (open_new_tab). After both substitutions are made, any empty
216+
# strings in the transformed remote_args list will be removed.
209217
remote_args = ['%action', '%s']
210218
remote_action = None
211219
remote_action_newwin = None
212220
remote_action_newtab = None
213-
background = False
214-
redirect_stdout = True
215221

216222
def _invoke(self, args, remote, autoraise):
217223
raise_opt = []
@@ -267,6 +273,7 @@ def open(self, url, new=0, autoraise=True):
267273

268274
args = [arg.replace("%s", url).replace("%action", action)
269275
for arg in self.remote_args]
276+
args = [arg for arg in args if arg]
270277
success = self._invoke(args, True, autoraise)
271278
if not success:
272279
# remote invocation failed, try straight way

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ Core and Builtins
115115
Library
116116
-------
117117

118+
- Issue #15509: webbrowser.UnixBrowser no longer passes empty arguments to
119+
Popen when %action substitutions produce empty strings.
120+
118121
- Issue #12776,#11839: call argparse type function (specified by add_argument)
119122
only once. Before, the type function was called twice in the case where the
120123
default was specified and the argument was given as well. This was

0 commit comments

Comments
 (0)