gh-135661: Fix parsing attributes with whitespaces around the "=" sep… · python/cpython@dee6501

GitHub

@@ -623,7 +623,7 @@ def test_correct_detection_of_start_tags(self):

623623624624html='<div style="", foo = "bar" ><b>The <a href="some_url">rain</a>'

625625expected= [

626- ('starttag', 'div', [('style', ''), (',', None), ('foo', None), ('=', None), ('"bar"', None)]),

626+ ('starttag', 'div', [('style', ''), (',', None), ('foo', 'bar')]),

627627 ('starttag', 'b', []),

628628 ('data', 'The '),

629629 ('starttag', 'a', [('href', 'some_url')]),

@@ -813,12 +813,12 @@ def test_attr_syntax(self):

813813 ]

814814self._run_check("""<a b='v' c="v" d=v e>""", output)

815815self._run_check("<a foo==bar>", [('starttag', 'a', [('foo', '=bar')])])

816-self._run_check("<a foo =bar>", [('starttag', 'a', [('foo', None), ('=bar', None)])])

817-self._run_check("<a foo\t=bar>", [('starttag', 'a', [('foo', None), ('=bar', None)])])

816+self._run_check("<a foo =bar>", [('starttag', 'a', [('foo', 'bar')])])

817+self._run_check("<a foo\t=bar>", [('starttag', 'a', [('foo', 'bar')])])

818818self._run_check("<a foo\v=bar>", [('starttag', 'a', [('foo\v', 'bar')])])

819819self._run_check("<a foo\xa0=bar>", [('starttag', 'a', [('foo\xa0', 'bar')])])

820-self._run_check("<a foo= bar>", [('starttag', 'a', [('foo', ''), ('bar', None)])])

821-self._run_check("<a foo=\tbar>", [('starttag', 'a', [('foo', ''), ('bar', None)])])

820+self._run_check("<a foo= bar>", [('starttag', 'a', [('foo', 'bar')])])

821+self._run_check("<a foo=\tbar>", [('starttag', 'a', [('foo', 'bar')])])

822822self._run_check("<a foo=\vbar>", [('starttag', 'a', [('foo', '\vbar')])])

823823self._run_check("<a foo=\xa0bar>", [('starttag', 'a', [('foo', '\xa0bar')])])

824824@@ -829,8 +829,8 @@ def test_attr_values(self):

829829 ("d", "\txyz\n")])])

830830self._run_check("""<a b='' c="">""",

831831 [("starttag", "a", [("b", ""), ("c", "")])])

832-self._run_check("<a b=\t c=\n>",

833- [("starttag", "a", [("b", ""), ("c", "")])])

832+self._run_check("<a b=\tx c=\ny>",

833+ [('starttag', 'a', [('b', 'x'), ('c', 'y')])])

834834self._run_check("<a b=\v c=\xa0>",

835835 [("starttag", "a", [("b", "\v"), ("c", "\xa0")])])

836836# Regression test for SF patch #669683.

@@ -899,13 +899,17 @@ def test_malformed_attributes(self):

899899 )

900900expected= [

901901 ('starttag', 'a', [('href', "test'style='color:red;bad1'")]),

902- ('data', 'test - bad1'), ('endtag', 'a'),

902+ ('data', 'test - bad1'),

903+ ('endtag', 'a'),

903904 ('starttag', 'a', [('href', "test'+style='color:red;ba2'")]),

904- ('data', 'test - bad2'), ('endtag', 'a'),

905+ ('data', 'test - bad2'),

906+ ('endtag', 'a'),

905907 ('starttag', 'a', [('href', "test'\xa0style='color:red;bad3'")]),

906- ('data', 'test - bad3'), ('endtag', 'a'),

907- ('starttag', 'a', [('href', None), ('=', None), ("test'&nbsp;style", 'color:red;bad4')]),

908- ('data', 'test - bad4'), ('endtag', 'a')

908+ ('data', 'test - bad3'),

909+ ('endtag', 'a'),

910+ ('starttag', 'a', [('href', "test'\xa0style='color:red;bad4'")]),

911+ ('data', 'test - bad4'),

912+ ('endtag', 'a'),

909913 ]

910914self._run_check(html, expected)

911915