From a3f6610112178020ffb8c44cf122b98d134779af Mon Sep 17 00:00:00 2001 From: niftylettuce Date: Mon, 11 Mar 2019 17:23:41 -0500 Subject: [PATCH] fix: fixed core bug with getPreservedText (closes #328) --- lib/cheerio.js | 2 +- lib/inline.js | 4 ++-- lib/utils.js | 4 ++-- test/cases/juice-content/height-attr.html | 4 ++-- test/cases/juice-content/height-attr.out | 4 ++-- test/cases/juice-content/width-attr.html | 4 ++-- test/cases/juice-content/width-attr.out | 4 ++-- test/juice.test.js | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/cheerio.js b/lib/cheerio.js index afc5efd..d5d861a 100644 --- a/lib/cheerio.js +++ b/lib/cheerio.js @@ -1,5 +1,5 @@ 'use strict'; - + /** * Module dependencies. */ diff --git a/lib/inline.js b/lib/inline.js index c86940c..2899c04 100644 --- a/lib/inline.js +++ b/lib/inline.js @@ -352,8 +352,8 @@ function getStylesData($, options) { mediaQueries: options.preserveMediaQueries, fontFaces: options.preserveFontFaces, keyFrames: options.preserveKeyFrames, - pseudos: juiceClient.ignoredPseudos - }); + pseudos: options.preservePseudos + }, juiceClient.ignoredPseudos); if (preservedText) { styleElement.childNodes[0].nodeValue = preservedText; } else { diff --git a/lib/utils.js b/lib/utils.js index 632e10d..051e1eb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -85,7 +85,7 @@ exports.parseCSS = function(css) { * @api public */ -exports.getPreservedText = function(css, options) { +exports.getPreservedText = function(css, options, ignoredPseudos) { var parsed = mensch.parse(css, {position: true, comments: true}); var rules = typeof parsed.stylesheet != 'undefined' && parsed.stylesheet.rules ? parsed.stylesheet.rules : []; var preserved = []; @@ -95,7 +95,7 @@ exports.getPreservedText = function(css, options) { if ((options.fontFaces && rules[i].type === 'font-face') || (options.mediaQueries && rules[i].type === 'media') || (options.keyFrames && rules[i].type === 'keyframes') || - (options.pseudos && rules[i].selectors && this.matchesPseudo(rules[i].selectors[0], options.pseudos))) { + (options.pseudos && rules[i].selectors && this.matchesPseudo(rules[i].selectors[0], ignoredPseudos))) { preserved.unshift( mensch.stringify( { stylesheet: { rules: [ rules[i] ] }}, diff --git a/test/cases/juice-content/height-attr.html b/test/cases/juice-content/height-attr.html index 7ae678a..d9d626c 100644 --- a/test/cases/juice-content/height-attr.html +++ b/test/cases/juice-content/height-attr.html @@ -29,7 +29,7 @@ - high - high + high + high diff --git a/test/cases/juice-content/height-attr.out b/test/cases/juice-content/height-attr.out index fcf210b..c3ecd38 100644 --- a/test/cases/juice-content/height-attr.out +++ b/test/cases/juice-content/height-attr.out @@ -22,7 +22,7 @@ - high - high + high + high diff --git a/test/cases/juice-content/width-attr.html b/test/cases/juice-content/width-attr.html index b08dc46..3dcd2b2 100644 --- a/test/cases/juice-content/width-attr.html +++ b/test/cases/juice-content/width-attr.html @@ -29,7 +29,7 @@ - wide - wide + wide + wide diff --git a/test/cases/juice-content/width-attr.out b/test/cases/juice-content/width-attr.out index a3b25e3..90f3dee 100644 --- a/test/cases/juice-content/width-attr.out +++ b/test/cases/juice-content/width-attr.out @@ -22,7 +22,7 @@ - wide - wide + wide + wide diff --git a/test/juice.test.js b/test/juice.test.js index 78c9fa4..a8ebc9f 100644 --- a/test/juice.test.js +++ b/test/juice.test.js @@ -189,6 +189,6 @@ it('test style attributes and important priority', function() { it('test that preserved text order is stable', function() { assert.deepEqual( - utils.getPreservedText('div { color: red; } @media (min-width: 320px) { div { color: green; } } @media (max-width: 640px) { div { color: blue; } }', { mediaQueries: true }).replace(/\s+/g, ' '), + utils.getPreservedText('div { color: red; } @media (min-width: 320px) { div { color: green; } } @media (max-width: 640px) { div { color: blue; } }', { mediaQueries: true }, juice.ignoredPseudos).replace(/\s+/g, ' '), ' @media (min-width: 320px) { div { color: green; } } @media (max-width: 640px) { div { color: blue; } } '); -}); \ No newline at end of file +});