Skip to content

Commit

Permalink
move 'match all' logic to matchRequestProps logic
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 1, 2022
1 parent 88e0d03 commit 545d6b3
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/helpers/match-request-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
* @returns {boolean}
*/
export const matchRequestProps = (propsToMatch, requestData) => {
if (propsToMatch === '' || propsToMatch === '*') {
return true;
}

let isMatched;

const parsedData = parseMatchProps(propsToMatch);
Expand Down
3 changes: 0 additions & 3 deletions src/scriptlets/prevent-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re
// log if no propsToMatch given
const logMessage = `log: fetch( ${objectToString(fetchData)} )`;
hit(source, logMessage);
} else if (propsToMatch === '' || propsToMatch === getWildcardSymbol()) {
// prevent all fetch calls
shouldPrevent = true;
} else {
shouldPrevent = matchRequestProps(propsToMatch);
}
Expand Down
3 changes: 0 additions & 3 deletions src/scriptlets/prevent-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ export function preventXHR(source, propsToMatch, customResponseText) {
// Log if no propsToMatch given
const logMessage = `log: xhr( ${objectToString(xhrData)} )`;
hit(source, logMessage);
} else if (propsToMatch === '' || propsToMatch === getWildcardSymbol()) {
// Prevent all fetch calls
shouldPrevent = true;
} else {
shouldPrevent = matchRequestProps(propsToMatch);
}
Expand Down
3 changes: 0 additions & 3 deletions src/scriptlets/trusted-replace-fetch-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ export function trustedReplaceFetchResponse(source, pattern = '', replacement =
const logMessage = `log: fetch( ${objectToString(fetchData)} )`;
log(source, logMessage);
hit(source);
} else if (propsToMatch === '' || propsToMatch === getWildcardSymbol()) {
// match all fetch calls
shouldReplace = true;
} else {
shouldReplace = matchRequestProps(propsToMatch, fetchData);
}
Expand Down

0 comments on commit 545d6b3

Please sign in to comment.