@@ -5,8 +5,11 @@ const _MS_PER_DAY = 1000 * 60 * 60 * 24; // Milliseconds per day.
55
66$ . fn . safeClone = function ( ) {
77 var $clone = this . clone ( ) ;
8- // IE BUG : Placeholder text becomes actual value after deep clone on textarea
8+ // IE 9-11 BUG : Placeholder text becomes actual value after deep clone on textarea
99 // https://connect.microsoft.com/IE/feedback/details/781612/placeholder-text-becomes-actual-value-after-deep-clone-on-textarea
10+ // Ref:
11+ // https://github.com/Patternslib/Patterns/issues/412
12+ // https://github.com/Patternslib/Patterns/pull/410
1013 if ( window . document . documentMode ) {
1114 $clone . findInclusive ( ":input[placeholder]" ) . each ( function ( i , item ) {
1215 var $item = $ ( item ) ;
@@ -589,7 +592,9 @@ const localized_isodate = (date) => {
589592 * Replace HTML reserved characters with html entities to add HTML for user
590593 * editing to e.g. a textarea or a contenteditable.
591594 *
592- * See: https://developer.mozilla.org/en-US/docs/Glossary/Entity#reserved_characters
595+ * See:
596+ * https://stackoverflow.com/a/22706073/1337474
597+ * https://developer.mozilla.org/en-US/docs/Glossary/Entity#reserved_characters
593598 *
594599 * @param {string } html - The HTML string to encode.
595600 *
@@ -600,17 +605,21 @@ const localized_isodate = (date) => {
600605 * ``"`` will be replaced with ``"``.
601606 */
602607const escape_html = ( html ) => {
603- return ( html || "" )
604- . replace ( / & / g, "&" ) // needs to be first!
605- . replace ( / < / g, "<" )
606- . replace ( / > / g, ">" )
607- . replace ( / " / g, """ ) ;
608+ if ( ! html ) {
609+ return "" ;
610+ }
611+ const el = document . createElement ( "div" ) ;
612+ el . appendChild ( document . createTextNode ( html ) ) ;
613+ // Return escaped html and also replace quotes.
614+ return el . innerHTML . replace ( / " / g, """ ) ;
608615} ;
609616
610617/**
611618 * Return unescaped, raw HTML from an escaped HTML string.
612619 *
613- * See: https://developer.mozilla.org/en-US/docs/Glossary/Entity#reserved_characters
620+ * See:
621+ * https://stackoverflow.com/a/34064434/1337474
622+ * https://developer.mozilla.org/en-US/docs/Glossary/Entity#reserved_characters
614623 *
615624 * @param {string } escaped_html - The HTML string to decode.
616625 *
@@ -621,11 +630,12 @@ const escape_html = (html) => {
621630 * ``"`` will be replaced with ``"``.
622631 */
623632const unescape_html = ( escaped_html ) => {
624- return ( escaped_html || "" )
625- . replace ( / & a m p ; / g, "&" )
626- . replace ( / & l t ; / g, "<" )
627- . replace ( / & g t ; / g, ">" )
628- . replace ( / & q u o t ; / g, '"' ) ;
633+ if ( ! escaped_html ) {
634+ return "" ;
635+ }
636+ const doc = new DOMParser ( ) . parseFromString ( escaped_html , "text/html" ) ;
637+ // Return unescaped html and also unescape quote named entities.
638+ return doc . documentElement . textContent . replace ( / & q u o t ; / g, '"' ) ;
629639} ;
630640
631641/**
0 commit comments