From: Teemu Suo-Anttila Date: Thu, 7 Nov 2013 09:32:28 +0000 (+0200) Subject: Support special characters in quotes in locators (#12738). X-Git-Tag: 7.2.0.beta1~169^2~5^2~5^2^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d2e7b366ef40bd5a27ba4693eba8d80ae8fc4f77;p=vaadin-framework.git Support special characters in quotes in locators (#12738). Change-Id: I5674bfdab3a5ff3ff9799178bbf9e187fa7ea544 --- diff --git a/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java b/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java index 96374e898a..95b2745bf8 100644 --- a/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java +++ b/client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java @@ -192,9 +192,10 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { * @return The predicate string for the path fragment or null if none. */ private String extractPredicateString(String pathFragment) { - int ixOpenBracket = pathFragment.indexOf('['); + int ixOpenBracket = indexOfIgnoringQuotes(pathFragment, '['); if (ixOpenBracket >= 0) { - int ixCloseBracket = pathFragment.indexOf(']', ixOpenBracket); + int ixCloseBracket = indexOfIgnoringQuotes(pathFragment, ']', + ixOpenBracket); return pathFragment.substring(ixOpenBracket + 1, ixCloseBracket); } return null; @@ -376,7 +377,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { * the path. */ private String[] splitFirstFragmentFromTheRest(String path) { - int ixOfSlash = path.indexOf('/'); + int ixOfSlash = indexOfIgnoringQuotes(path, '/'); if (ixOfSlash > 0) { return new String[] { path.substring(0, ixOfSlash), path.substring(ixOfSlash) }; @@ -384,4 +385,31 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy { return new String[] { path }; } + private int indexOfIgnoringQuotes(String str, char find) { + return indexOfIgnoringQuotes(str, find, 0); + } + + private int indexOfIgnoringQuotes(String str, char find, int startingAt) { + boolean quote = false; + String quoteChars = "'\""; + char currentQuote = '"'; + for (int i = startingAt; i < str.length(); ++i) { + char cur = str.charAt(i); + if (quote) { + if (cur == currentQuote) { + quote = !quote; + } + continue; + } else if (cur == find) { + return i; + } else { + if (quoteChars.indexOf(cur) >= 0) { + currentQuote = cur; + quote = !quote; + } + } + } + return -1; + } + }