Skip to content

Commit

Permalink
Check that document selectors are actually simple selectors
Browse files Browse the repository at this point in the history
Checking for `/deep/` and `::shadow` is not enough

Fixes #4885
  • Loading branch information
dfreedm committed Oct 17, 2017
1 parent 5c0df2d commit ad7805e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/style-transformer.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
},

_transformDocumentSelector: function(selector) {
return selector.match(SCOPE_JUMP) ?
return (selector.match(SCOPE_JUMP) || selector.match(SIMPLE_SELECTOR_SEP) )?
this._transformComplexSelector(selector, SCOPE_DOC_SELECTOR) :
this._transformSimpleSelector(selector.trim(), SCOPE_DOC_SELECTOR);
},
Expand Down
6 changes: 5 additions & 1 deletion test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@
'unit/dir.html',
'unit/dir.html?dom=shadow',
'unit/dir.html?lazyRegister=true&useNativeCSSProperties=true',
'unit/dir.html?lazyRegister=true&useNativeCSSProperties=true&dom=shadow'
'unit/dir.html?lazyRegister=true&useNativeCSSProperties=true&dom=shadow',
'unit/custom-style-transformed.html',
'unit/custom-style-transformed.html?dom=shadow',
'unit/custom-style-transformed.html?lazyRegister=true&useNativeCSSProperties=true',
'unit/custom-style-transformed.html?lazyRegister=true&useNativeCSSProperties=true&dom=shadow'
];

if (window.customElements || document.registerElement) {
Expand Down
52 changes: 52 additions & 0 deletions test/unit/custom-style-transformed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!doctype html>
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html">
</head>
<body>
<style is="custom-style">
html:not([foo]) * {
color: rgb(123, 123, 123);
border: 10px solid black;
}
</style>
</body>
<dom-module id="x-styled">
<template>
<style>
:host {
display: block;
}
</style>
<div id="target"></div>
</template>
</dom-module>

<x-styled id="target"></x-styled>

<script>
HTMLImports.whenReady(function() {
Polymer({is: 'x-styled'});
});
suite('complicated custom style', function() {
test('complicated selector', function() {
var el = document.querySelector('x-styled#target');
var target = el.$.target;
assert.equal(getComputedStyle(el).getPropertyValue('border-top-width').trim(), '10px');
assert.equal(getComputedStyle(target).getPropertyValue('border-top-width').trim(), '0px');
assert.equal(getComputedStyle(target).getPropertyValue('color').trim(), 'rgb(123, 123, 123)');
})
})
</script>

0 comments on commit ad7805e

Please sign in to comment.