WordPress.org

Make WordPress Core

Opened 4 weeks ago

Last modified 12 days ago

#40635 new enhancement

Move JavaScript `sanitizeText` and `stripTags` functions from press-this to core

Reported by: adamsilverstein Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch needs-unit-tests
Focuses: javascript Cc:

Description

The file press-this.js includes two generally useful helper functions:

  • stripTags strips HTML tags from a string using a series of regex replace calls.
  • sanitizeText strips HTML tags and converts HTML entities in a string. It leverages a textarea's content to encode HTML and returns a string that is safe to evaluate.

These functions would be generally useful in core and for plugin and theme developers and could be added to the wp namespace, eg wp.utils.stripTags and wp.utils.sanitizeText

Attachments (1)

40635.diff (3.6 KB) - added by adamsilverstein 4 weeks ago.

Download all attachments as: .zip

Change History (4)

#1 @adamsilverstein
4 weeks ago

  • Keywords has-patch needs-unit-tests added; needs-patch removed

40635.diff moves the sanitizeText and stripTags functions from wp-admin/js/press-this.js to wp-includes/js/utils.js and namespaces them as wp.utils.sanitizeText and wp.utils.stripTags.

Some unit tests for these helpers would be a great addition, if we have them I couldn't find them.

#2 @afercia
4 weeks ago

+1 for wp.utils.

This ticket was mentioned in Slack in #core by adamsilverstein. View the logs.


12 days ago

Note: See TracTickets for help on using tickets.