]> source.dussan.org Git - vaadin-framework.git/commitdiff
Support special characters in quotes in locators (#12738).
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 7 Nov 2013 09:32:28 +0000 (11:32 +0200)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 7 Nov 2013 09:52:41 +0000 (09:52 +0000)
Change-Id: I5674bfdab3a5ff3ff9799178bbf9e187fa7ea544

client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java

index 96374e898a7ce405551275ffe2cb3cb6ae611ef6..95b2745bf80d07be205390dfae6c394124e9c1df 100644 (file)
@@ -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;
+    }
+
 }