~facelessuser/beautifulsoup/self-check

« back to all changes in this revision

Viewing changes to bs4/testing.py

  • Committer: Leonard Richardson
  • Date: 2018-12-31 02:13:03 UTC
  • Revision ID: leonardr@segfault.org-20181231021303-ms9mi6u6x2xkw7lz
Fixed a problem with multi-valued attributes where the value
  contained whitespace. Thanks to Jens Svalgaard for the
  fix. [bug=1787453]

Show diffs side-by-side

added added

removed removed

Lines of Context:
452
452
            "<tbody><tr><td>Bar</td></tr></tbody>"
453
453
            "<tfoot><tr><td>Baz</td></tr></tfoot></table>")
454
454
 
 
455
    def test_multivalued_attribute_with_whitespace(self):
 
456
        # Whitespace separating the values of a multi-valued attribute
 
457
        # should be ignored.
 
458
 
 
459
        markup = '<div class=" foo bar   "></a>'
 
460
        soup = self.soup(markup)
 
461
        self.assertEqual(['foo', 'bar'], soup.div['class'])
 
462
 
 
463
        # If you search by the literal name of the class it's like the whitespace
 
464
        # wasn't there.
 
465
        self.assertEqual(soup.div, soup.find('div', class_="foo bar"))
 
466
        
455
467
    def test_deeply_nested_multivalued_attribute(self):
456
468
        # html5lib can set the attributes of the same tag many times
457
469
        # as it rearranges the tree. This has caused problems with