{"record":{"id":"0f297990835ed473","repo":"koala73/worldmonitor","slug":"invalid-sitemap-entries-location","errorCode":null,"errorMessage":"invalid sitemap entries: ${location}","messagePattern":"invalid sitemap entries: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/seo-indexnow-submit.mjs","lineNumber":188,"sourceCode":"      throw new Error(`invalid sitemap location: ${location}`);\n    }\n    if (seen.has(location)) continue;\n    seen.add(location);\n    if (seen.size > 50) throw new Error('published sitemap tree exceeds 50 documents');\n    const response = await fetchImpl(location, {\n      method: 'GET',\n      redirect: 'manual',\n      signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),\n      headers: { Accept: 'application/xml', 'User-Agent': USER_AGENT },\n    });\n    if (response.status !== 200) throw new Error(`${location} returned ${response.status}, expected direct 200`);\n    const source = (await response.text()).trim();\n    const root = /^(?:<\\?xml[^?]*\\?>\\s*)?<(sitemapindex|urlset)\\b[^>]*>([\\s\\S]*)<\\/\\1>\\s*$/.exec(source);\n    if (!root) throw new Error(`invalid sitemap document: ${location}`);\n    const tag = root[1] === 'sitemapindex' ? 'sitemap' : 'url';\n    const entryPattern = new RegExp(`<!--[\\\\s\\\\S]*?-->|<${tag}>[\\\\s\\\\S]*?<\\\\/${tag}>`, 'g');\n    const entries = [...root[2].matchAll(entryPattern)].filter(([entry]) => !entry.startsWith('<!--'));\n    if (root[2].replace(entryPattern, '').trim()) throw new Error(`invalid sitemap entries: ${location}`);\n    const urls = entries.map(([entry]) => {\n      const locations = [...entry.matchAll(/<loc>\\s*([^<]+?)\\s*<\\/loc>/g)];\n      if (locations.length !== 1) throw new Error(`expected one location per sitemap entry: ${location}`);\n      return decodeXml(locations[0][1].trim());\n    });\n    if (urls.length === 0) throw new Error(`empty sitemap: ${location}`);\n    if (location === `${origin}/sitemap.xml`\n      && (root[1] !== 'sitemapindex' || urls.length !== SITEMAP_INDEX_MEMBERS.length\n        || new Set(urls).size !== urls.length || urls.some(url => !SITEMAP_INDEX_MEMBERS.includes(url)))) {\n      throw new Error('published root sitemap members do not match the declared inventory');\n    }\n    if (root[1] === 'sitemapindex') {\n      pending.push(...urls);\n    } else {\n      for (const url of urls) {\n        const page = new URL(url);\n        if (page.protocol !== 'https:' || !hosts.has(page.host) || page.username || page.password || page.hash || page.pathname.endsWith('.xml')) {\n          throw new Error(`invalid published page URL: ${url}`);","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/scripts/seo-indexnow-submit.mjs#L170-L206","documentation":"Within a recognized sitemap root the script strips comments and block-level <sitemap>/<url> tags via regex; if any non-whitespace content remains between/after those tags the document has unexpected inter-tag content and the script throws 'invalid sitemap entries: <location>', rejecting loosely-structured or injected markup.","triggerScenarios":"The sitemap body contains stray text, unknown tags (e.g. custom elements between <url> blocks), unclosed or malformed <url> elements that the regex does not consume, CDATA or processing instructions outside the recognized pattern — anything left over after removing comments and tag blocks.","commonSituations":"Custom CMS injecting extra nodes into the sitemap; a template bug emitting text between <url> elements; sitemap edited by hand with invalid markup; an XML feature (CDATA sections, DOCTYPE entities) the simple regex parser does not model.","solutions":["Validate the sitemap against the sitemaps.org XSD and fix the generator to emit only standard <url>/<sitemap> children","Remove stray text/unknown elements between the recognized tags","Avoid hand-editing published sitemaps; regenerate them from the source of truth","If the sitemap legitimately uses XML features the regex parser rejects, simplify the emitted markup to plain <loc> children"],"exampleFix":"// before\n<urlset>\n  <url><loc>https://example.com/a</loc></url>\n  generated by FooPlugin v2\n  <url><loc>https://example.com/b</loc></url>\n</urlset>\n// after\n<urlset>\n  <url><loc>https://example.com/a</loc></url>\n  <url><loc>https://example.com/b</loc></url>\n</urlset>","handlingStrategy":"validation","validationCode":"const xml = (await (await fetch(url)).text()).trim();\nconst doc = new DOMParser().parseFromString(xml, 'application/xml');\nif (doc.querySelector('parsererror')) console.warn(`${url}: malformed XML`);","typeGuard":null,"tryCatchPattern":"try {\n  await getPublishedBatches();\n} catch (err) {\n  if (err.message.startsWith('invalid sitemap entries:')) {\n    const loc = err.message.split(': ').slice(1).join(': ');\n    logger.error({ loc }, 'unexpected content between sitemap tags');\n  } else throw err;\n}","preventionTips":["Emit only standard <url>/<sitemap> children with <loc> inside","Run sitemaps through XSD validation in CI","Never hand-edit published sitemap files"],"tags":["seo","sitemap","xml"],"backgroundTag":"xml-parse-error","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}