Skip to content

Commit

Permalink
Clone attributes in shallowClone()
Browse files Browse the repository at this point in the history
  • Loading branch information
Summers, Ian M. (S&T-Student) authored and jhy committed May 12, 2019
1 parent 82e2c44 commit eaf876d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jsoup/nodes/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ public Element clone() {
@Override
public Element shallowClone() {
// simpler than implementing a clone version with no child copy
return new Element(tag, baseUri, attributes);
return new Element(tag, baseUri, attributes == null ? null : attributes.clone());
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/jsoup/nodes/ElementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,13 @@ public class ElementTest {

assertEquals(1, p.childNodeSize());
assertEquals(0, p2.childNodeSize());

assertEquals("", p2.text());
assertEquals("One", t2.text());

assertEquals("two", p2.className());
assertEquals("One", t2.text());
p2.removeClass("two");
assertEquals("two", p.className());

d2.append("<p id=3>Three");
assertEquals(1, d2.childNodeSize());
Expand Down

0 comments on commit eaf876d

Please sign in to comment.