@@ -2614,16 +2614,16 @@ function isAnyValueRegexStartsWith(values) {
2614
2614
});
2615
2615
}
2616
2616
2617
- function createLiteralRegex(remaining) {
2617
+ function createLiteralRegex(remaining: string ) {
2618
2618
return remaining
2619
2619
.split('')
2620
2620
.map(c => {
2621
- const regex = RegExp('[0-9 ]|\\p{L}', 'u'); // Support all unicode letter chars
2621
+ const regex = RegExp('[0-9 ]|\\p{L}', 'u'); // Support all Unicode letter chars
2622
2622
if (c.match(regex) !== null) {
2623
- // don 't escape alphanumeric characters
2623
+ // Don 't escape alphanumeric characters
2624
2624
return c;
2625
2625
}
2626
- // escape everything else (single quotes with single quotes, everything else with a backslash)
2626
+ // Escape everything else (single quotes with single quotes, everything else with a backslash)
2627
2627
return c === ` '` ? ` ''` : `\\${ c } ` ;
2628
2628
} )
2629
2629
. join ( '' ) ;
@@ -2633,14 +2633,14 @@ function literalizeRegexPart(s: string) {
2633
2633
const matcher1 = / \\Q ( ( ?! \\E ) . * ) \\E$ / ;
2634
2634
const result1 : any = s . match ( matcher1 ) ;
2635
2635
if ( result1 && result1 . length > 1 && result1 . index > - 1 ) {
2636
- // process regex that has a beginning and an end specified for the literal text
2636
+ // Process Regex that has a beginning and an end specified for the literal text
2637
2637
const prefix = s . substring ( 0 , result1 . index ) ;
2638
2638
const remaining = result1 [ 1 ] ;
2639
2639
2640
2640
return literalizeRegexPart ( prefix ) + createLiteralRegex ( remaining ) ;
2641
2641
}
2642
2642
2643
- // process regex that has a beginning specified for the literal text
2643
+ // Process Regex that has a beginning specified for the literal text
2644
2644
const matcher2 = / \\ Q ( (? ! \\ E ) .* ) $ / ;
2645
2645
const result2 : any = s . match ( matcher2 ) ;
2646
2646
if ( result2 && result2 . length > 1 && result2 . index > - 1 ) {
@@ -2650,14 +2650,18 @@ function literalizeRegexPart(s: string) {
2650
2650
return literalizeRegexPart ( prefix ) + createLiteralRegex ( remaining ) ;
2651
2651
}
2652
2652
2653
- // remove all instances of \Q and \E from the remaining text & escape single quotes
2653
+ // Remove problematic chars from remaining text
2654
2654
return s
2655
+ // Remove all instances of \Q and \E
2655
2656
. replace ( / ( [ ^ \\ ] ) ( \\ E ) / , '$1' )
2656
2657
. replace ( / ( [ ^ \\ ] ) ( \\ Q ) / , '$1' )
2657
2658
. replace ( / ^ \\ E / , '' )
2658
2659
. replace ( / ^ \\ Q / , '' )
2659
- . replace ( / ( [ ^ ' ] ) ' / g, `$1''` )
2660
- . replace ( / ^ ' ( [ ^ ' ] ) / , `''$1` ) ;
2660
+ // Ensure even number of single quote sequences by adding an extra single quote if needed;
2661
+ // this ensures that every single quote is escaped
2662
+ . replace ( / ' + / g, match => {
2663
+ return match . length % 2 === 0 ? match : match + "'" ;
2664
+ } ) ;
2661
2665
}
2662
2666
2663
2667
var GeoPointCoder = {
0 commit comments