Skip to content

Commit

Permalink
fix: fixed core bug with getPreservedText (closes #328)
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Mar 11, 2019
1 parent ce4aa01 commit a3f6610
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/cheerio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

/**
* Module dependencies.
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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] ] }},
Expand Down
4 changes: 2 additions & 2 deletions test/cases/juice-content/height-attr.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</td>
</tr>
</table>
<img src="" alt="high" class="px">
<img src="" alt="high" class="percentage">
<img src alt="high" class="px">
<img src alt="high" class="percentage">
</body>
</html>
4 changes: 2 additions & 2 deletions test/cases/juice-content/height-attr.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</td>
</tr>
</table>
<img src="" alt="high" class="px" style="height: 200px;" height="200">
<img src="" alt="high" class="percentage" style="height: 50%;">
<img src alt="high" class="px" style="height: 200px;" height="200">
<img src alt="high" class="percentage" style="height: 50%;">
</body>
</html>
4 changes: 2 additions & 2 deletions test/cases/juice-content/width-attr.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</td>
</tr>
</table>
<img src="" alt="wide" class="px">
<img src="" alt="wide" class="percentage">
<img src alt="wide" class="px">
<img src alt="wide" class="percentage">
</body>
</html>
4 changes: 2 additions & 2 deletions test/cases/juice-content/width-attr.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</td>
</tr>
</table>
<img src="" alt="wide" class="px" style="width: 200px;" width="200">
<img src="" alt="wide" class="percentage" style="width: 50%;">
<img src alt="wide" class="px" style="width: 200px;" width="200">
<img src alt="wide" class="percentage" style="width: 50%;">
</body>
</html>
4 changes: 2 additions & 2 deletions test/juice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; } } ');
});
});

0 comments on commit a3f6610

Please sign in to comment.