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

WAT: only unescape complete XML/HTML character entities #19

Closed
sebastian-nagel opened this issue Aug 19, 2019 · 2 comments

Comments

@sebastian-nagel
Copy link

commented Aug 19, 2019

Decoding of XML/HTML character entities (see #14) should be done in a safe way and only if they are complete. A sequence &or (in &order=lexical) must not be treated as entity ∨.

The Translate.decode(...) method of htmlparser.org is not safe in this point as it does not require a closing `;'.

@sebastian-nagel

This comment has been minimized.

Copy link
Author

commented Aug 27, 2019

Note that only malformed URLs are mangled, the ampersand should be escaped also in HTML element attributes. Of course, this is a frequent error in HTML and invalid URLs/links might be cumbersome in case they're used to feed a crawler, construct a webgraph, etc.

When extracting text a lazy replacement (without a closing ;) is sometimes a good choice, eg. for sequences such as &nsp&nsp&nsp.

sebastian-nagel added a commit that referenced this issue Aug 28, 2019
WAT: only unescape complete XML/HTML character entities (fixes #19)
- replace org.htmlparser's decode method by Apache commons-text `unescapeHtml4`
sebastian-nagel added a commit that referenced this issue Aug 28, 2019
WAT: only unescape complete XML/HTML character entities (fixes #19)
- use jsoup's Parser.unescapeEntities(...) instead which
  * supports HTML 5 entities
  * provides a safer mode when entities in attributes are decoded
@sebastian-nagel

This comment has been minimized.

Copy link
Author

commented Aug 28, 2019

Finally fixed using jsoup's Parser.unescapeEntities(...) instead which

  • supports HTML 5 entities and all other entities
  • provides a "safe" mode when entities in attributes are decoded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.