-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/v1.7' into fix/AG-14514
- Loading branch information
Showing
22 changed files
with
1,817 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
getMatchPropsData, | ||
validateParsedData, | ||
parseMatchProps, | ||
} from './request-utils'; | ||
|
||
/** | ||
* Checks if given propsToMatch string matches with given request data | ||
* This is used by prevent-xhr, prevent-fetch, trusted-replace-xhr-response | ||
* and trusted-replace-fetch-response scriptlets | ||
* @param {string} propsToMatch | ||
* @param {Object} requestData object with standard properties of fetch/xhr like url, method etc | ||
* @returns {boolean} | ||
*/ | ||
export const matchRequestProps = (propsToMatch, requestData) => { | ||
let isMatched; | ||
|
||
const parsedData = parseMatchProps(propsToMatch); | ||
if (!validateParsedData(parsedData)) { | ||
// eslint-disable-next-line no-console | ||
console.log(`Invalid parameter: ${propsToMatch}`); | ||
isMatched = false; | ||
} else { | ||
const matchData = getMatchPropsData(parsedData); | ||
// prevent only if all props match | ||
isMatched = Object.keys(matchData) | ||
.every((matchKey) => { | ||
const matchValue = matchData[matchKey]; | ||
return Object.prototype.hasOwnProperty.call(requestData, matchKey) | ||
&& matchValue.test(requestData[matchKey]); | ||
}); | ||
} | ||
|
||
return isMatched; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.