From 99625950c8ceb78e652d2ac52e5dc4e521ae6a39 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 21 Jan 2021 02:27:15 -0500 Subject: [PATCH] contentcollector: Factor out call to `.toLowerCase()` --- src/static/js/contentcollector.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index a717df3a3..9f60b9033 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -43,7 +43,8 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) // .tagName works with DOM and cheerio 0.22.0, but: // * With DOM, .tagName is an uppercase string. // * With cheerio 0.22.0, .tagName is a lowercase string. - nodeTagName: (n) => n.tagName, + // For consistency, this function always returns a lowercase string. + nodeTagName: (n) => n.tagName && n.tagName.toLowerCase(), // .nodeValue works with DOM and cheerio 0.22.0. nodeValue: (n) => n.nodeValue, // Returns the number of Node children (n.childNodes.length), not the number of Element children @@ -88,7 +89,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) _blockElems[element] = 1; }); - const isBlockElement = (n) => !!_blockElems[(dom.nodeTagName(n) || '').toLowerCase()]; + const isBlockElement = (n) => !!_blockElems[dom.nodeTagName(n) || '']; const textify = (str) => sanitizeUnicode( str.replace(/(\n | \n)/g, ' ') @@ -406,7 +407,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) } } } else { - const tname = (dom.nodeTagName(node) || '').toLowerCase(); + const tname = dom.nodeTagName(node) || ''; if (tname === 'img') { hooks.callAll('collectContentImage', {