Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix favicon function and add error handling #933

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions docker/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ exports.CONSTANTS = {
};

exports.handleNoFavIcon = (result) => {
// Check if array contains an item with message: 'Found'
let foundItem = result.find(item => item.message === this.CONSTANTS.FoundFavIconMsg);

if (foundItem) {
// If favicon found, remove all 'Not Found' items and 'Found' itself
return result.filter(item => item.message !== this.CONSTANTS.FoundFavIconMsg && item.message !== this.CONSTANTS.NoFavIconMsg);
} else {
// If favicon not found, return as it is
return result
// Get root result
if (result[0]?.length) {
// Check if array contains an item with message: 'Found'
let foundItem = result[0].find(item => item.message === this.CONSTANTS.FoundFavIconMsg);

if (foundItem) {
// If favicon found, remove all 'Not Found' items and 'Found' itself
result[0] = result[0].filter(item => item.message !== this.CONSTANTS.FoundFavIconMsg && item.message !== this.CONSTANTS.NoFavIconMsg);
}
}
}

Expand Down Expand Up @@ -183,7 +183,7 @@ exports.runCodeAuditor = (ignorefile, rulesfolder) => {
* Send GET request and then perform HTML Hint check on it
* @param {string} url - URL to scan
*/
const runHtmlHint = async (url, rules, customRuleOptions) => {
const runHtmlHint = async (url, rules, customRuleOptions, writeLog) => {
const { HTMLHint } = require("htmlhint");
const selectedRules = new Set(rules?.selectedRules?.split(",").filter(i => i));
const ignoredRules = new Set(
Expand Down Expand Up @@ -225,7 +225,8 @@ const runHtmlHint = async (url, rules, customRuleOptions) => {
})
)(html);
} catch (error) {
return null;
writeLog(`Error fetching URL: ${url} - ${error.message}`);
return [];
}
};

Expand Down Expand Up @@ -462,11 +463,11 @@ exports.runHtmlHint = async (startUrl, scannedUrls, writeLog, tokenApi) => {
const customRuleOptions = await getCustomHtmlRuleOptions(tokenApi, startUrl);

let result = await Promise.all(
allGoodLinks.map((x) => runHtmlHint(x, rules, customRuleOptions))
allGoodLinks.map((x) => runHtmlHint(x, rules, customRuleOptions, writeLog))
);

if (result) {
result = this.handleNoFavIcon(result[0]);
this.handleNoFavIcon(result);
const selectedRules = rules?.selectedRules ?? Object.keys(htmlHintConfig).join(",");

const [summary, details] = getHtmlHintDetails(result);
Expand Down
Loading