handle non-utf8 html document and their URLs#370
Conversation
9556b70 to
1d564da
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #370 +/- ##
==========================================
+ Coverage 51.66% 55.21% +3.55%
==========================================
Files 115 117 +2
Lines 7131 7257 +126
==========================================
+ Hits 3684 4007 +323
+ Misses 3154 2930 -224
- Partials 293 320 +27
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR implements support for handling non-UTF-8 HTML documents and their URLs by adding character encoding detection and proper URL encoding. It addresses the challenge of correctly processing web content that uses legacy character encodings like GBK, Shift_JIS, or Windows-1252.
- Adds character encoding detection for HTML documents using golang.org/x/net/html/charset
- Implements proper URL query parameter encoding based on document character encoding
- Refactors HTML processing to use a new document transformation pipeline
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/models/url.go | Adds document caching and encoding fields to URL struct with corresponding getters/setters |
| pkg/models/item.go | Updates method call to use new document cache API |
| internal/pkg/postprocessor/item.go | Adds document cache cleanup in post-processing |
| internal/pkg/postprocessor/extractor/html_document.go | New file implementing character encoding detection and URL encoding logic |
| internal/pkg/postprocessor/extractor/html_document_test.go | Comprehensive test coverage for encoding detection and URL encoding functions |
| internal/pkg/postprocessor/extractor/html.go | Updates HTML extraction to use new document transformation and refactors asset extraction code |
| e2e/test/nonutf8encoding/ | End-to-end test files for validating GBK encoding handling |
Comments suppressed due to low confidence (1)
e2e/test/nonutf8encoding/testdata/gbk.html:4
- The test data file contains Chinese characters that appear to be displayed incorrectly (showing as question marks or boxes). This suggests the file may not be saved in GBK encoding as intended, which could affect the validity of the test.
<title>GBK �����ҳ��</title>
NGTmeaty
left a comment
There was a problem hiding this comment.
Couple of small comments otherwise looks great!
NGTmeaty
left a comment
There was a problem hiding this comment.
Looks great! Thank you for the changes and tests!
close #169
Some temporary references:
HTML:
html encoding:
https://encoding.spec.whatwg.org (spec, en)
→ https://html.spec.whatwg.org/multipage/parsing.html#determining-the-character-encoding (spec, en)
→ https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-charset (spec, en)
https://en.wikipedia.org/wiki/Windows-1252 (wiki, en)
https://www.xiaogd.net/md/web-page-encoding-and-mojibake-1 (blog, zh)
https://httptoolkit.com/blog/http-encodings/ (blog, en)
URL:
https://html.spec.whatwg.org/multipage/urls-and-fetching.html#resolving-urls
https://url.spec.whatwg.org/#query-state
https://url.spec.whatwg.org/#path-state