@@ -625,34 +625,23 @@ builtinScriptlets.push({
625
625
] ,
626
626
} ) ;
627
627
function matchObjectProperties ( propNeedles , ...objs ) {
628
- if ( matchObjectProperties . extractProperties === undefined ) {
629
- matchObjectProperties . extractProperties = ( src , des , props ) => {
630
- for ( const p of props ) {
631
- const v = src [ p ] ;
632
- if ( v === undefined ) { continue ; }
633
- des [ p ] = src [ p ] ;
634
- }
635
- } ;
636
- }
637
628
const safe = safeSelf ( ) ;
638
- const haystack = { } ;
639
- const props = safe . Array_from ( propNeedles . keys ( ) ) ;
629
+ const matched = [ ] ;
640
630
for ( const obj of objs ) {
641
631
if ( obj instanceof Object === false ) { continue ; }
642
- matchObjectProperties . extractProperties ( obj , haystack , props ) ;
643
- }
644
- for ( const [ prop , details ] of propNeedles ) {
645
- let value = haystack [ prop ] ;
646
- if ( value === undefined ) { continue ; }
647
- if ( typeof value !== 'string' ) {
648
- try { value = safe . JSON_stringify ( value ) ; }
649
- catch { }
650
- if ( typeof value !== 'string' ) { continue ; }
651
- }
652
- if ( safe . testPattern ( details , value ) ) { continue ; }
653
- return false ;
632
+ for ( const [ prop , details ] of propNeedles ) {
633
+ let value = obj [ prop ] ;
634
+ if ( value === undefined ) { continue ; }
635
+ if ( typeof value !== 'string' ) {
636
+ try { value = safe . JSON_stringify ( value ) ; }
637
+ catch { }
638
+ if ( typeof value !== 'string' ) { continue ; }
639
+ }
640
+ if ( safe . testPattern ( details , value ) === false ) { return ; }
641
+ matched . push ( `${ prop } : ${ value } ` ) ;
642
+ }
654
643
}
655
- return true ;
644
+ return matched ;
656
645
}
657
646
658
647
/******************************************************************************/
@@ -679,7 +668,6 @@ function jsonPruneFetchResponseFn(
679
668
const logall = rawPrunePaths === '' ;
680
669
const applyHandler = function ( target , thisArg , args ) {
681
670
const fetchPromise = Reflect . apply ( target , thisArg , args ) ;
682
- let outcome = logall ? 'nomatch' : 'match' ;
683
671
if ( propNeedles . size !== 0 ) {
684
672
const objs = [ args [ 0 ] instanceof Object ? args [ 0 ] : { url : args [ 0 ] } ] ;
685
673
if ( objs [ 0 ] instanceof Request ) {
@@ -692,14 +680,12 @@ function jsonPruneFetchResponseFn(
692
680
if ( args [ 1 ] instanceof Object ) {
693
681
objs . push ( args [ 1 ] ) ;
694
682
}
695
- if ( matchObjectProperties ( propNeedles , ...objs ) === false ) {
696
- outcome = 'nomatch' ;
683
+ const matched = matchObjectProperties ( propNeedles , ...objs ) ;
684
+ if ( matched === undefined ) { return fetchPromise ; }
685
+ if ( safe . logLevel > 1 ) {
686
+ safe . uboLog ( logPrefix , `Matched "propsToMatch":\n\t${ matched . join ( '\n\t' ) } ` ) ;
697
687
}
698
688
}
699
- if ( logall === false && outcome === 'nomatch' ) { return fetchPromise ; }
700
- if ( safe . logLevel > 1 && outcome !== 'nomatch' && propNeedles . size !== 0 ) {
701
- safe . uboLog ( logPrefix , `Matched optional "propsToMatch"\n${ extraArgs . propsToMatch } ` ) ;
702
- }
703
689
return fetchPromise . then ( responseBefore => {
704
690
const response = responseBefore . clone ( ) ;
705
691
return response . json ( ) . then ( objBefore => {
@@ -772,7 +758,6 @@ function replaceFetchResponseFn(
772
758
apply : function ( target , thisArg , args ) {
773
759
const fetchPromise = Reflect . apply ( target , thisArg , args ) ;
774
760
if ( pattern === '' ) { return fetchPromise ; }
775
- let outcome = 'match' ;
776
761
if ( propNeedles . size !== 0 ) {
777
762
const objs = [ args [ 0 ] instanceof Object ? args [ 0 ] : { url : args [ 0 ] } ] ;
778
763
if ( objs [ 0 ] instanceof Request ) {
@@ -786,23 +771,20 @@ function replaceFetchResponseFn(
786
771
if ( args [ 1 ] instanceof Object ) {
787
772
objs . push ( args [ 1 ] ) ;
788
773
}
789
- if ( matchObjectProperties ( propNeedles , ...objs ) === false ) {
790
- outcome = 'nomatch' ;
774
+ const matched = matchObjectProperties ( propNeedles , ...objs ) ;
775
+ if ( matched === undefined ) { return fetchPromise ; }
776
+ if ( safe . logLevel > 1 ) {
777
+ safe . uboLog ( logPrefix , `Matched "propsToMatch":\n\t${ matched . join ( '\n\t' ) } ` ) ;
791
778
}
792
779
}
793
- if ( outcome === 'nomatch' ) { return fetchPromise ; }
794
- if ( safe . logLevel > 1 ) {
795
- safe . uboLog ( logPrefix , `Matched "propsToMatch"\n${ propsToMatch } ` ) ;
796
- }
797
780
return fetchPromise . then ( responseBefore => {
798
781
const response = responseBefore . clone ( ) ;
799
782
return response . text ( ) . then ( textBefore => {
800
783
if ( reIncludes && reIncludes . test ( textBefore ) === false ) {
801
784
return responseBefore ;
802
785
}
803
786
const textAfter = textBefore . replace ( rePattern , replacement ) ;
804
- const outcome = textAfter !== textBefore ? 'match' : 'nomatch' ;
805
- if ( outcome === 'nomatch' ) { return responseBefore ; }
787
+ if ( textAfter === textBefore ) { return responseBefore ; }
806
788
safe . uboLog ( logPrefix , 'Replaced' ) ;
807
789
const responseAfter = new Response ( textAfter , {
808
790
status : responseBefore . status ,
@@ -1399,7 +1381,7 @@ function jsonPruneXhrResponse(
1399
1381
const xhrDetails = { method, url } ;
1400
1382
let outcome = 'match' ;
1401
1383
if ( propNeedles . size !== 0 ) {
1402
- if ( matchObjectProperties ( propNeedles , xhrDetails ) === false ) {
1384
+ if ( matchObjectProperties ( propNeedles , xhrDetails ) === undefined ) {
1403
1385
outcome = 'nomatch' ;
1404
1386
}
1405
1387
}
@@ -2838,7 +2820,7 @@ function trustedReplaceXhrResponse(
2838
2820
const xhrDetails = { method, url } ;
2839
2821
let outcome = 'match' ;
2840
2822
if ( propNeedles . size !== 0 ) {
2841
- if ( matchObjectProperties ( propNeedles , xhrDetails ) === false ) {
2823
+ if ( matchObjectProperties ( propNeedles , xhrDetails ) === undefined ) {
2842
2824
outcome = 'nomatch' ;
2843
2825
}
2844
2826
}
0 commit comments