Skip to content

Commit

Permalink
improve responseType checking condition
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed May 10, 2023
1 parent 68f3b60 commit c21eccc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/scriptlets/prevent-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,18 @@ export function preventFetch(source, propsToMatch, responseBody = 'emptyObj', re
return;
}

const isResponseTypeSpecified = typeof responseType !== 'undefined';
const isResponseTypeSupported = (responseType) => {
const SUPPORTED_TYPES = [
'default',
'opaque',
];
return SUPPORTED_TYPES.includes(responseType);
};
// Skip disallowed response types,
// specified responseType has limited list of possible values
if (typeof responseType !== 'undefined'
&& !(responseType === 'default' || responseType === 'opaque')) {
if (isResponseTypeSpecified
&& !isResponseTypeSupported(responseType)) {
logMessage(source, `Invalid responseType parameter: '${responseType}'`);
return;
}
Expand Down

0 comments on commit c21eccc

Please sign in to comment.