@@ -985,10 +985,39 @@ public static XPathLocator pageHeader(String headerText)
985985 * Direct port from attibuteValue function in selenium IDE locatorBuilders.js
986986 * @param value to be quoted
987987 * @return value with either ' or " around it or assembled from parts
988+ * @implNote {@link Quotes#escape(String)} doesn't handle trailing quotes correctly
988989 */
989990 public static String xq (String value )
990991 {
991- return Quotes .escape (value );
992+ if (!value .contains ("'" )) {
993+ return "'" + value + "'" ;
994+ } else if (!value .contains ("\" " )) {
995+ return '"' + value + '"' ;
996+ } else {
997+ StringBuilder result = new StringBuilder ("concat(" );
998+ while (true ) {
999+ int apos = value .indexOf ("'" );
1000+ int quot = value .indexOf ('"' );
1001+ if (apos < 0 ) {
1002+ result .append ("'" ).append (value ).append ("'" );
1003+ break ;
1004+ } else if (quot < 0 ) {
1005+ result .append ('"' ).append (value ).append ('"' );
1006+ break ;
1007+ } else if (quot < apos ) {
1008+ String part = value .substring (0 , apos );
1009+ result .append ("'" ).append (part ).append ("'" );
1010+ value = value .substring (part .length ());
1011+ } else {
1012+ String part = value .substring (0 , quot );
1013+ result .append ('"' ).append (part ).append ('"' );
1014+ value = value .substring (part .length ());
1015+ }
1016+ result .append (',' );
1017+ }
1018+ result .append (')' );
1019+ return result .toString ();
1020+ }
9921021 }
9931022
9941023 /**
0 commit comments