Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(web platform): Do not barf on attribute selectors.
Browse files Browse the repository at this point in the history
See #1189
  • Loading branch information
jbdeboer committed Jun 28, 2014
1 parent 5cb46a1 commit f2b8393
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/core_dom/web_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ class WebPlatform {

void shimShadowDom(dom.Element root, String selector) {
if (shadowDomShimRequired) {

// This adds an empty attribute with the name of the component tag onto
// each element in the shadow root.
root.querySelectorAll("*")
.forEach((n) => n.attributes[selector] = "");
//
// Remove the try-catch once https://github.com/angular/angular.dart/issues/1189 is
// fixed.
try {
root.querySelectorAll("*")
.forEach((n) => n.attributes[selector] = "");
} catch (e, s) {
print("WARNING: Failed to set up Shadow DOM shim for $selector.\n$e\n$s");
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/core_dom/web_platform_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ main() {
beforeEachModule((Module module) {
module
..bind(WebPlatformTestComponent)
..bind(WebPlatformTestComponentWithAttribute)
..bind(InnerComponent)
..bind(OuterComponent)
..bind(WebPlatform, toValue: new WebPlatform());
Expand Down Expand Up @@ -54,6 +55,24 @@ main() {
}
}));

it('should not crash with an attribute selector; but wont work either..',
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {

backend
..expectGET('style.css').respond(200, 'span { background-color: red; '
'}')
..expectGET('template.html').respond(200, '<span>foo</span>');

Element element = e('<span><test-wptca a><span>ignore'
'</span></test-wptca></span>');

_.compile(element);

microLeap();
backend.flush();
microLeap();
}));

it('should scope :host styles to the primary element.',
async((TestBed _, MockHttpBackend backend, WebPlatform platform) {

Expand Down Expand Up @@ -176,6 +195,14 @@ main() {
class WebPlatformTestComponent {
}

@Component(
selector: "test-wptca[a]",
publishAs: "ctrl",
templateUrl: "template.html",
cssUrl: "style.css")
class WebPlatformTestComponentWithAttribute {
}

@Component(
selector: "my-inner",
publishAs: "ctrl",
Expand Down

0 comments on commit f2b8393

Please sign in to comment.