DocsGPT icon indicating copy to clipboard operation
DocsGPT copied to clipboard

Bug report - Sitemap loader misses valid XML namespace declarations

Open IlyaKhalafi opened this issue 1 month ago • 5 comments

Description

SitemapLoader._parse_sitemap removes one default namespace with a regular expression before parsing XML. It only recognizes xmlns="...". Valid single-quoted declarations, whitespace around =, and namespace prefixes leave qualified tags in the tree, so the unqualified searches find no page URLs or nested sitemaps.

The same preprocessing decodes every document as UTF-8, ignoring the XML encoding declaration.

Reproduction

from docsgpt.parser.remote.sitemap_loader import SitemapLoader

xml = b"<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'><url><loc>https://example.com/docs</loc></url></urlset>"
urls = SitemapLoader()._parse_sitemap(xml)
print(urls)
assert urls == ["https://example.com/docs"]

The same failure occurs with prefixed <sm:urlset>, <sm:url> and <sm:loc> elements. A prefixed sitemap index also fails to follow its child sitemap.

Expected behavior

Equivalent XML namespace declarations yield the same URLs. Parsing the original bytes also lets the XML parser honor its encoding declaration.

Actual behavior

The reproduction returns []. Five regression cases fail locally, covering single quotes, whitespace, prefixed page entries, prefixed sitemap indexes, and declared ISO-8859-1 encoding.

Environment

Linux, Python 3.12.3, editable local development installation from the current main checkout. No database or network access is needed to reproduce the parser failure.

This is separate from the recursion and depth-limit issue in #3036 and its PR #3038. It only concerns XML parsing and namespace lookup.

  • [x] Searched existing issues and PRs without finding this defect.
  • [x] Reproduced locally.

A focused fix and regression tests are ready to prepare.

Checked against main commit 9c4251e3bd33637913ba08e2c6f13f21ef200a09.

IlyaKhalafi avatar Oct 12 '26 20:10 IlyaKhalafi

Hi! I'd like to work on this bug for Hacktoberfest if it's still available.

I've looked at the issue: the sitemap loader's regex-based namespace stripping misses valid XML namespace declarations. My plan is to fix the namespace handling in sitemap_loader.py so all valid declarations are recognized, plus a regression test covering the cases from the issue.

Could you please assign it to me? Thanks!

devilking7x avatar Oct 13 '26 04:10 devilking7x

@devilking7x, PRs #3077 and #3078 already address this issue, so I haven't assigned it. You can help by testing either fix or reviewing the changes.

Automated triage. A maintainer will follow up.

arc53-machine avatar Oct 13 '26 04:10 arc53-machine

Hey @arc53-machine, I'd like to work on this issue. Could you please assign it to me? Thanks!

satanic47 avatar Oct 13 '26 23:10 satanic47

@satanic47, PRs #3077 and #3078 already address this issue, so I haven't assigned it. You can help by testing either fix or reviewing the changes.

Automated triage. A maintainer will follow up.

arc53-machine avatar Oct 13 '26 23:10 arc53-machine

Fixed by #3156, which rebuilt the sitemap reader as part of the Website source work. All five cases in your report pass on main. It didn't link this issue, which is why this stayed open.

Thanks for the report.

ManishMadan2882 avatar Oct 28 '26 10:10 ManishMadan2882