]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #29290: argparse help messages won't wrap at non-breaking spaces.
authorXiang Zhang <angwerzx@126.com>
Sun, 22 Jan 2017 06:37:22 +0000 (14:37 +0800)
committerXiang Zhang <angwerzx@126.com>
Sun, 22 Jan 2017 06:37:22 +0000 (14:37 +0800)
Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS

index 9a067196dac3ffb6c413a1f144a5180fd2c6ccdc..0d881b8d3ef93a6c3b0dc28d2724bf528fbf88d8 100644 (file)
@@ -176,7 +176,7 @@ class HelpFormatter(object):
         self._root_section = self._Section(self, None)
         self._current_section = self._root_section
 
-        self._whitespace_matcher = _re.compile(r'\s+')
+        self._whitespace_matcher = _re.compile(r'\s+', _re.ASCII)
         self._long_break_matcher = _re.compile(r'\n\n\n+')
 
     # ===============================
index 4779a133012597b2596f33d47997aa69bb076d16..197d576eb665c0f5e43a19adc717de452d9025fa 100644 (file)
@@ -1943,6 +1943,23 @@ class TestAddSubparsers(TestCase):
               ++foo       foo help
             '''))
 
+    def test_help_non_breaking_spaces(self):
+        parser = ErrorRaisingArgumentParser(
+            prog='PROG', description='main description')
+        parser.add_argument(
+            "--non-breaking", action='store_false',
+            help='help message containing non-breaking spaces shall not '
+            'wrap\N{NO-BREAK SPACE}at non-breaking spaces')
+        self.assertEqual(parser.format_help(), textwrap.dedent('''\
+            usage: PROG [-h] [--non-breaking]
+
+            main description
+
+            optional arguments:
+              -h, --help      show this help message and exit
+              --non-breaking  help message containing non-breaking spaces shall not
+                              wrap\N{NO-BREAK SPACE}at non-breaking spaces
+        '''))
 
     def test_help_alternate_prefix_chars(self):
         parser = self._get_parser(prefix_chars='+:/')
index 84fa9d1b9fda9c2df62504d88ab4c87454066e90..d2a839054546c096f0cae81f97f239b52682e032 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,9 +13,12 @@ Core and Builtins
 Library
 -------
 
+- Issue #29290: Fix a regression in argparse that help messages would wrap at
+  non-breaking spaces.
+
 - Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.
 
-- Issue #29011:  Fix an important omission by adding Deque to the typing module.
+- Issue #29011: Fix an important omission by adding Deque to the typing module.
 
 - Issue #29219: Fixed infinite recursion in the repr of uninitialized
   ctypes.CDLL instances.