From 69ea45e34b36e2afc1cea5b0aab21ad392c7c4bc Mon Sep 17 00:00:00 2001 From: Megaman Date: Fri, 23 Nov 2018 19:43:01 +0800 Subject: [PATCH 1/2] Update Autolinker.js --- src/Autolinker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Autolinker.js b/src/Autolinker.js index fe53cc8b..d27f6013 100644 --- a/src/Autolinker.js +++ b/src/Autolinker.js @@ -610,7 +610,7 @@ Autolinker.prototype = { var node = htmlNodes[ i ], nodeType = node.getType(); - if( nodeType === 'element' && node.getTagName() === 'a' ) { // Process HTML anchor element nodes in the input `textOrHtml` to find out when we're within an tag + if( nodeType === 'element' && (node.getTagName() === 'a' || node.getTagName() === 'style') ) { // Process HTML anchor element nodes in the input `textOrHtml` to find out when we're within an tag if( !node.isClosing() ) { // it's the start tag anchorTagStackCount++; } else { // it's the end tag From 6030e17034f4effb403f96226323398cfef94278 Mon Sep 17 00:00:00 2001 From: Megaman Date: Sat, 24 Nov 2018 11:15:11 +0800 Subject: [PATCH 2/2] skip parsing style and script tag skip parsing style and script tag --- src/Autolinker.js | 10 +++++----- tests/AutolinkerSpec.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Autolinker.js b/src/Autolinker.js index d27f6013..0043ab94 100644 --- a/src/Autolinker.js +++ b/src/Autolinker.js @@ -605,19 +605,19 @@ Autolinker.prototype = { matches = []; // Find all matches within the `textOrHtml` (but not matches that are - // already nested within tags) + // already nested within , or tag anchorTagStackCount = Math.max( anchorTagStackCount - 1, 0 ); // attempt to handle extraneous tags by making sure the stack count never goes below 0 } - } else if( nodeType === 'text' && anchorTagStackCount === 0 ) { // Process text nodes that are not within an tag + } else if( nodeType === 'text' && anchorTagStackCount === 0 ) { // Process text nodes that are not within an , tags' ); + expect( result ).toBe( 'Testing with tags' ); + } ); + + + it( "should NOT automatically link a URL found within the inner text of a script tag", function() { + var result = autolinker.link( 'Testing with tags' ); + expect( result ).toBe( 'Testing with tags' ); + } ); + + it( "should NOT automatically link an image tag with a URL inside of it, when it has another attribute which has extraneous spaces surround its value (Issue #45)", function() { var result = autolinker.link( "Testing " ); expect( result ).toBe( "Testing " );