Skip to content

Commit

Permalink
fix: unexpected close tag issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiAlexandruParaschiv committed Aug 20, 2024
1 parent 8ca17d7 commit 818d9ce
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/sitemap/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ export async function checkRobotsForSitemap(protocol, domain, log) {
* @returns {boolean} - True if the sitemap content is valid, otherwise false.
*/
export function isSitemapContentValid(sitemapContent) {
return sitemapContent.payload.trim().startsWith('<?xml')
|| VALID_MIME_TYPES.some((type) => sitemapContent.type.includes(type));
const payload = sitemapContent.payload.trim();

// Check if the content is HTML and return false if it is
if (payload.startsWith('<!DOCTYPE html>') || payload.startsWith('<html')) {
return false;
}

// Only consider it valid if it's XML
return payload.startsWith('<?xml') && VALID_MIME_TYPES.some((type) => sitemapContent.type.includes(type));
}

/**
Expand Down Expand Up @@ -150,14 +157,15 @@ export async function checkSitemap(sitemapUrl, log) {

const isValidFormat = isSitemapContentValid(sitemapContent);
if (!isValidFormat) {
log.error(`Invalid sitemap format at ${sitemapUrl}`);
log.error(`Invalid sitemap format or non-sitemap content at ${sitemapUrl}`);
return {
existsAndIsValid: false,
reasons: [ERROR_CODES.SITEMAP_FORMAT],
details: { sitemapContent: {}, isText: false, isSitemapIndex: false },
};
}

// Additional processing logic
const isSitemapIndex = sitemapContent.payload.includes('</sitemapindex>');
const isText = sitemapContent.type === 'text/plain';

Expand Down

0 comments on commit 818d9ce

Please sign in to comment.