Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: tools/telemetry/telemetry/page/actions/click_element.py

Issue 100283003: Escape selectors before evaluating them (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/telemetry/telemetry/page/actions/click_element_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/page/actions/click_element.py
diff --git a/tools/telemetry/telemetry/page/actions/click_element.py b/tools/telemetry/telemetry/page/actions/click_element.py
index abfbd9370f8eeeecd45a3b12dc1f9a0ac33b8df7..91339c76fd375589ade8665ef956356ac2471342 100644
--- a/tools/telemetry/telemetry/page/actions/click_element.py
+++ b/tools/telemetry/telemetry/page/actions/click_element.py
@@ -8,6 +8,9 @@ from telemetry.core import util
from telemetry.core import exceptions
from telemetry.page.actions import page_action
+def _EscapeSelector(selector):
+ return selector.replace('\'', '\\\'')
+
class ClickElementAction(page_action.PageAction):
def __init__(self, attributes=None):
super(ClickElementAction, self).__init__(attributes)
@@ -15,7 +18,8 @@ class ClickElementAction(page_action.PageAction):
def RunAction(self, page, tab, previous_action):
def DoClick():
if hasattr(self, 'selector'):
- code = 'document.querySelector(\'' + self.selector + '\').click();'
+ code = ('document.querySelector(\'' + _EscapeSelector(self.selector) +
+ '\').click();')
try:
tab.ExecuteJavaScript(code)
except exceptions.EvaluateException:
« no previous file with comments | « no previous file | tools/telemetry/telemetry/page/actions/click_element_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698