From 9b8d3bd54d0fa1e8c0989483a3cda5fa371c9c84 Mon Sep 17 00:00:00 2001 From: Mikhail Kobzarev Date: Wed, 3 May 2023 11:17:23 +0300 Subject: [PATCH] Fix ampersand conversion in links --- mihdan-no-external-links.php | 4 ++-- public/Frontend.php | 2 +- public/js/seo-hide.js | 34 ++++++++++++++-------------------- readme.txt | 8 ++++++-- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/mihdan-no-external-links.php b/mihdan-no-external-links.php index e64ff88..0c5436e 100644 --- a/mihdan-no-external-links.php +++ b/mihdan-no-external-links.php @@ -10,7 +10,7 @@ * Plugin Name: Mihdan: No External Links * Plugin URI: https://wordpress.org/plugins/mihdan-no-external-links/ * Description: Convert external links into internal links, site wide or post/page specific. Add NoFollow, Click logging, and more... - * Version: 5.0.6 + * Version: 5.0.7 * Author: Mikhail Kobzarev * Author URI: https://www.kobzarev.com/ * License: GPL-2.0+ @@ -28,7 +28,7 @@ } const MIHDAN_NO_EXTERNAL_LINKS_DIR = __DIR__; -const MIHDAN_NO_EXTERNAL_LINKS_VERSION = '5.0.6'; +const MIHDAN_NO_EXTERNAL_LINKS_VERSION = '5.0.7'; const MIHDAN_NO_EXTERNAL_LINKS_SLUG = 'mihdan-no-external-links'; define( 'MIHDAN_NO_EXTERNAL_LINKS_BASENAME', plugin_basename( __FILE__ ) ); diff --git a/public/Frontend.php b/public/Frontend.php index 6b8d4d0..07af3c6 100644 --- a/public/Frontend.php +++ b/public/Frontend.php @@ -321,7 +321,7 @@ public function mask_link( $matches ): string { preg_match( '/class="([^"]+)"/si', $attributes, $maybe_classes ); - if ( $maybe_classes[1] ) { + if ( ! empty( $maybe_classes[1] ) ) { $classes .= ' ' . $maybe_classes[1]; } diff --git a/public/js/seo-hide.js b/public/js/seo-hide.js index 7a8aadf..0fa0241 100644 --- a/public/js/seo-hide.js +++ b/public/js/seo-hide.js @@ -23,26 +23,20 @@ } ); - function basePropertyOf( object ) { - return function ( key ) { - return object == null ? undefined : object[ key ]; - }; - } - - var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, - reHasEscapedHtml = RegExp( reEscapedHtml.source ), - htmlUnescapes = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - ''': "'" - }, - unescapeHtmlChar = basePropertyOf( htmlUnescapes ); - + /** + * Decode HTML entities. + * + * Example: + * - & -> & + * - & -> & + * + * @param text String for decoding. + * @returns {string} + */ function decodeHTMLEntities( text ) { - return ( text && reHasEscapedHtml.test( text ) ) - ? text.replace( reEscapedHtml, unescapeHtmlChar ) - : text; + const textArea = document.createElement( 'textarea' ); + textArea.innerHTML = text; + + return textArea.value; } } )( window, document ); diff --git a/readme.txt b/readme.txt index bd4e539..08e4894 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: mihdan, kaggdesign Tags: seo, seo-hide, link, links, publisher, post, posts, comments Requires at least: 5.7.4 Tested up to: 6.2 -Stable tag: 5.0.6 +Stable tag: 5.0.7 Requires PHP: 7.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -63,7 +63,11 @@ Mihdan: No External Links **does not** make any changes to your database, it jus == Changelog == -= 5.0.6 (03.05.2023) = += 5.0.7 (03.05.2023) = +* Fixed ampersand conversion in links +* Fixed PHP notices + += 5.0.6 (02.05.2023) = * Resolve #[20](https://github.com/mihdan/mihdan-no-external-links/issues/20) * Resolve #[25](https://github.com/mihdan/mihdan-no-external-links/issues/25) * Resolve #[30](https://github.com/mihdan/mihdan-no-external-links/issues/30)