From 5169e3418622453d7b8e2a96cd2aa908578f3a20 Mon Sep 17 00:00:00 2001 From: Juliangzr <45461158+Juliangzr@users.noreply.github.com> Date: Thu, 29 Nov 2018 14:12:06 -0300 Subject: [PATCH] avoid error "Cannot read property 'match' of null" I had a problem when trying to use the library, issue reported in Issue ID #187 --- index.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 8f82c83..b44b744 100644 --- a/index.js +++ b/index.js @@ -109,20 +109,23 @@ Pjax.prototype = { // since we are forced to use documentElement.innerHTML (outerHTML can't be used for ) var htmlRegex = /]+>/gi var htmlAttribsRegex = /\s?[a-z:]+(?:\=(?:\'|\")[^\'\">]+(?:\'|\"))*/gi - var matches = html.match(htmlRegex) - if (matches && matches.length) { - matches = matches[0].match(htmlAttribsRegex) - if (matches.length) { - matches.shift() - matches.forEach(function(htmlAttrib) { - var attr = htmlAttrib.trim().split("=") - if (attr.length === 1) { - tmpEl.documentElement.setAttribute(attr[0], true) - } - else { - tmpEl.documentElement.setAttribute(attr[0], attr[1].slice(1, -1)) - } - }) + + if (html != undefined) { + var matches = html.match(htmlRegex) + if (matches && matches.length) { + matches = matches[0].match(htmlAttribsRegex) + if (matches.length) { + matches.shift() + matches.forEach(function(htmlAttrib) { + var attr = htmlAttrib.trim().split("=") + if (attr.length === 1) { + tmpEl.documentElement.setAttribute(attr[0], true) + } + else { + tmpEl.documentElement.setAttribute(attr[0], attr[1].slice(1, -1)) + } + }) + } } }