Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use try catch to protect querySelector #12734

Merged
merged 3 commits into from Jan 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions extensions/amp-analytics/0.1/analytics-root.js
Expand Up @@ -210,13 +210,18 @@ export class AnalyticsRoot {
let found;
let result = null;
// Query search based on the selection method.
if (selectionMethod == 'scope') {
found = scopedQuerySelector(context, selector);
} else if (selectionMethod == 'closest') {
found = closestBySelector(context, selector);
} else {
found = this.getRoot().querySelector(selector);
try {
if (selectionMethod == 'scope') {
found = scopedQuerySelector(context, selector);
} else if (selectionMethod == 'closest') {
found = closestBySelector(context, selector);
} else {
found = this.getRoot().querySelector(selector);
}
} catch (e) {
user().assert(false, `Invalid query selector ${selector}`);
}

// DOM search can "look" outside the boundaries of the root, thus make
// sure the result is contained.
if (found && this.contains(found)) {
Expand Down