Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy constructor of Safelist shares state #1764

Closed
cschwier opened this issue May 5, 2022 · 0 comments · Fixed by #1763
Closed

Copy constructor of Safelist shares state #1764

cschwier opened this issue May 5, 2022 · 0 comments · Fixed by #1763
Milestone

Comments

@cschwier
Copy link
Contributor

cschwier commented May 5, 2022

The copy constructor of Safelist public Safelist(Safelist copy) does not deep copy the data structures as advertised in the JavaDoc but shares the nested data structures, e.g. Map<TagName, Set<AttributeKey>>. This causes unexpected mutation.

An example would be:

Safelist safelist1 = Safelist.none().addAttributes("foo", "bar");
Safelist safelist2 = new Safelist(safelist1);
safelist1.addAttributes("foo", "baz");

final String html = "<foo bar=\"val\" baz=\"val\" />";
System.out.println(Jsoup.clean(html, safelist1));
System.out.println(Jsoup.clean(html, safelist2));

The second output should not contain the baz attribute but does.

@jhy jhy closed this as completed in #1763 May 15, 2022
@jhy jhy added this to the 1.15.1 milestone May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants