Skip to content

Commit

Permalink
Fix json-prune-xhr-response as per feedback
Browse files Browse the repository at this point in the history
Related commit:
abe4103
  • Loading branch information
gorhill committed Sep 6, 2023
1 parent 5c9c0a8 commit 14d60ac
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,25 +1365,41 @@ function jsonPruneXhrResponse(
if ( xhrDetails === undefined ) {
return innerResponse;
}
if ( typeof innerResponse !== 'object' ) {
xhrDetails.response = innerResponse;
if ( xhrDetails.response !== undefined ) {
return xhrDetails.response;
}
let outerResponse = xhrDetails.response;
if ( outerResponse !== undefined ) {
return outerResponse;
let objBefore;
if ( typeof innerResponse === 'object' ) {
objBefore = innerResponse;
} else if ( typeof innerResponse === 'string' ) {
try { objBefore = safe.jsonParse(innerResponse); }
catch(ex) { }
}
if ( typeof objBefore !== 'object' ) {
return (xhrDetails.response = innerResponse);
}
outerResponse = objectPrune(
innerResponse,
const objAfter = objectPrune(
objBefore,
rawPrunePaths,
rawNeedlePaths,
{ matchAll: true },
extraArgs
);
if ( typeof outerResponse !== 'object' ) {
let outerResponse;
if ( typeof objAfter === 'object' ) {
outerResponse = typeof innerResponse === 'string'
? safe.jsonStringify(objAfter)
: objAfter;
} else {
outerResponse = innerResponse;
}
xhrDetails.response = outerResponse;
return outerResponse;
return (xhrDetails.response = outerResponse);
}
get responseText() {
const response = this.response;
return typeof response !== 'string'
? super.responseText
: response;
}
};
}
Expand Down

0 comments on commit 14d60ac

Please sign in to comment.