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

feat(html): Add escape and unescape functions for HTML entities #3335

Merged
merged 6 commits into from
May 30, 2023

Conversation

lionel-rowe
Copy link
Contributor

Fixes #3329

@lino-levan
Copy link
Contributor

Maybe we should rename html_entities to just entities since it is in the html top level folder?

@iuioiua
Copy link
Contributor

iuioiua commented May 16, 2023

Maybe we should rename html_entities to just entities since it is in the html top level folder?

+1

@lionel-rowe lionel-rowe requested a review from kt3k as a code owner May 19, 2023 06:20
@lionel-rowe
Copy link
Contributor Author

Bikeshedding: encode/decode vs. escape/unescape vs [any other options]? I don't have a strong preference.

@lionel-rowe lionel-rowe changed the title feat(html): Add encodeHtmlEntities and decodeHtmlEntities functions feat(html): Add encode and decode functions for HTML entities May 19, 2023
@timreichen
Copy link
Contributor

+1 for escape and unescape

@lionel-rowe lionel-rowe changed the title feat(html): Add encode and decode functions for HTML entities feat(html): Add escape and unescape functions for HTML entities May 23, 2023
@lionel-rowe lionel-rowe force-pushed the html-entities branch 2 times, most recently from 4ffdfb3 to 27dcd21 Compare May 23, 2023 12:27
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kt3k
Copy link
Member

kt3k commented May 30, 2023

Memo:

@lionel-rowe
Copy link
Contributor Author

Memo:

Honorable mention also to htmlentities and html_entity_decode in PHP, which use a full list of named entities.

Also worth considering the bit of the HTML spec that deals with escaping text nodes and attribute nodes:

  1. Replace any occurrence of the & character by the string &.
  2. Replace any occurrences of the U+00A0 NO-BREAK SPACE character by the string  .
  3. If the algorithm was invoked in the attribute mode, replace any occurrences of the " character by the string ".
  4. If the algorithm was not invoked in the attribute mode, replace any occurrences of the < character by the string &lt;, and any occurrences of the > character by the string &gt;.

@kt3k
Copy link
Member

kt3k commented May 30, 2023

@lionel-rowe Thanks for your contribution!

@kt3k kt3k merged commit 6ab64b1 into denoland:main May 30, 2023
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 this pull request may close these issues.

Encode/decode HTML entities
5 participants