I found an undesired side effect in Cleaner; when working with a Document, some calls could update URL attributes on the input document instead of only on the cleaned output.
For example, with a standard safelist like Safelist.basic(), cleaning or validating a document containing a relative link could rewrite the input href to an absolute URL:
Document dirty = Jsoup.parseBodyFragment(
"<a href='/foo'>One</a>", "https://example.com/");
Cleaner cleaner = new Cleaner(Safelist.basic());
cleaner.clean(dirty); // or cleaner.isValid(dirty)
dirty.expectFirst("a").attr("href"); // became "https://example.com/foo"
The intention is that absolutizing applies only to the cleaned output document. The input document should be left as-is.
The fix is to remove side effects from Safelist attribute/protocol checks, and make Cleaner perform URL normalization explicitly when copying safe attributes into the output document.
I found an undesired side effect in
Cleaner; when working with aDocument, some calls could update URL attributes on the input document instead of only on the cleaned output.For example, with a standard safelist like
Safelist.basic(), cleaning or validating a document containing a relative link could rewrite the inputhrefto an absolute URL:The intention is that absolutizing applies only to the cleaned output document. The input document should be left as-is.
The fix is to remove side effects from
Safelistattribute/protocol checks, and makeCleanerperform URL normalization explicitly when copying safe attributes into the output document.