When a Tag is copied, multi-valued attribute value lists are not deeply copied
Bug #2067412 reported by
Chris Papademetrious
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
When a tag is copied with copy.copy() or the private _clone() method, multi-valued attribute value lists are not deeply copied. As a result, changes to a copied tag's value list also affect the original tag.
In this example, p1 is copied to p2, then a change to p1's "class" attribute affects p2:
====
import bs4
import copy
html_doc = '<p class="foo"/>'
soup = bs4.BeautifulSo
p1 = soup.find("p")
p2 = p1._clone()
p1.attrs[
print(f"p1: {p1}")
print(f"p2: {p2}")
====
Perhaps the value lists need to be copied using [:] syntax (or something similar).
To post a comment you must log in.
A good catch. This is fixed in revision 4aaacc0.