Bug report - Sitemap loader misses valid XML namespace declarations
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.
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, 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.
Hey @arc53-machine, I'd like to work on this issue. Could you please assign it to me? Thanks!
@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.
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.