From 0d1fe4e99639ab5eea90f29db5ef88c9658767de Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 12 Sep 2014 13:18:05 -0400 Subject: [PATCH] FIX: Long inline links without closing parens could get V8 stuck in an infinite loop. --- src/dialects/gruber.js | 12 +++++++----- test/features/links/missing_end_paren.json | 5 +++++ test/features/links/missing_end_paren.text | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 test/features/links/missing_end_paren.json create mode 100644 test/features/links/missing_end_paren.text diff --git a/src/dialects/gruber.js b/src/dialects/gruber.js index ab3326de..ad3a6a76 100644 --- a/src/dialects/gruber.js +++ b/src/dialects/gruber.js @@ -664,11 +664,13 @@ define(['../markdown_helpers', './dialect_helpers', '../parser'], function (Mark return [ consumed, link ]; } - m = text.match(new RegExp("^\\((" + urlRegexp + ")\\)")); - if (m && m[1]) { - consumed += m[0].length; - link = ["link", {href: m[1]}].concat(children); - return [consumed, link]; + if (text.indexOf('(') === 0 && text.indexOf(')') !== -1) { + m = text.match(new RegExp("^\\((" + urlRegexp + ")\\)")); + if (m && m[1]) { + consumed += m[0].length; + link = ["link", {href: m[1]}].concat(children); + return [consumed, link]; + } } // [Alt text][id] diff --git a/test/features/links/missing_end_paren.json b/test/features/links/missing_end_paren.json new file mode 100644 index 00000000..dd6b7b2f --- /dev/null +++ b/test/features/links/missing_end_paren.json @@ -0,0 +1,5 @@ +["html", + ["p", + "an inline link [like this](http://googlewebmastercentral.blogspot.ca/2014/05/understanding-web-pages-better.html can crash V8." + ] +] diff --git a/test/features/links/missing_end_paren.text b/test/features/links/missing_end_paren.text new file mode 100644 index 00000000..a6a5ea3e --- /dev/null +++ b/test/features/links/missing_end_paren.text @@ -0,0 +1 @@ +an inline link [like this](http://googlewebmastercentral.blogspot.ca/2014/05/understanding-web-pages-better.html can crash V8.