avoid error "Cannot read property 'match' of null" #198

Closed
Juliangzr wants to merge 1 commits from patch-1 into master

View File

@@ -109,20 +109,23 @@ Pjax.prototype = {
// since we are forced to use documentElement.innerHTML (outerHTML can't be used for <html>) // since we are forced to use documentElement.innerHTML (outerHTML can't be used for <html>)
var htmlRegex = /<html[^>]+>/gi var htmlRegex = /<html[^>]+>/gi
var htmlAttribsRegex = /\s?[a-z:]+(?:\=(?:\'|\")[^\'\">]+(?:\'|\"))*/gi var htmlAttribsRegex = /\s?[a-z:]+(?:\=(?:\'|\")[^\'\">]+(?:\'|\"))*/gi
var matches = html.match(htmlRegex)
if (matches && matches.length) { if (html != undefined) {
matches = matches[0].match(htmlAttribsRegex) var matches = html.match(htmlRegex)
if (matches.length) { if (matches && matches.length) {
matches.shift() matches = matches[0].match(htmlAttribsRegex)
matches.forEach(function(htmlAttrib) { if (matches.length) {
var attr = htmlAttrib.trim().split("=") matches.shift()
if (attr.length === 1) { matches.forEach(function(htmlAttrib) {
tmpEl.documentElement.setAttribute(attr[0], true) var attr = htmlAttrib.trim().split("=")
} if (attr.length === 1) {
else { tmpEl.documentElement.setAttribute(attr[0], true)
tmpEl.documentElement.setAttribute(attr[0], attr[1].slice(1, -1)) }
} else {
}) tmpEl.documentElement.setAttribute(attr[0], attr[1].slice(1, -1))
}
})
}
} }
} }