File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2820,6 +2820,11 @@ class ClientSelectorGenerator {
2820
2820
contextNode : Document | ShadowRoot
2821
2821
) : HTMLElement [ ] {
2822
2822
try {
2823
+ if ( ! this . isXPathSelector ( xpath ) ) {
2824
+ console . warn ( "Selector doesn't appear to be XPath:" , xpath ) ;
2825
+ return [ ] ;
2826
+ }
2827
+
2823
2828
const document =
2824
2829
contextNode instanceof ShadowRoot
2825
2830
? ( contextNode . host as HTMLElement ) . ownerDocument
@@ -2847,11 +2852,28 @@ class ClientSelectorGenerator {
2847
2852
}
2848
2853
}
2849
2854
2855
+ private isXPathSelector ( selector : string ) : boolean {
2856
+ return selector . startsWith ( '//' ) ||
2857
+ selector . startsWith ( '/' ) ||
2858
+ selector . startsWith ( './' ) ||
2859
+ selector . includes ( 'contains(@' ) ||
2860
+ selector . includes ( '[count(' ) ||
2861
+ selector . includes ( '@class=' ) ||
2862
+ selector . includes ( '@id=' ) ||
2863
+ selector . includes ( ' and ' ) ||
2864
+ selector . includes ( ' or ' ) ;
2865
+ }
2866
+
2850
2867
private fallbackXPathEvaluation (
2851
2868
xpath : string ,
2852
2869
contextNode : Document | ShadowRoot
2853
2870
) : HTMLElement [ ] {
2854
2871
try {
2872
+ if ( this . isXPathSelector ( xpath ) ) {
2873
+ console . warn ( "⚠️ Complex XPath not supported in fallback:" , xpath ) ;
2874
+ return [ ] ;
2875
+ }
2876
+
2855
2877
const simpleTagMatch = xpath . match ( / ^ \/ \/ ( \w + ) $ / ) ;
2856
2878
if ( simpleTagMatch ) {
2857
2879
const tagName = simpleTagMatch [ 1 ] ;
You can’t perform that action at this time.
0 commit comments