Commit aea35e2
committed
Fix malformed XML declarations in OPF/XML files causing Amazon E999 rejections
Amazon's Send-to-Kindle service was rejecting some EPUBs with E999 errors due
to malformed XML declarations containing excessive whitespace. Example:
<?xml version="1.0" encoding="UTF-8"?>
^^
Double space breaks Amazon's strict XML parser
Root cause: fix_encoding() only processed HTML/XHTML files and missed OPF/XML/NCX
files entirely. Additionally, the validation regex incorrectly accepted malformed
declarations with multiple consecutive spaces.
Changes to kindle_epub_fixer.py:
- Extended fix_encoding() to process OPF, XML, and NCX files (not just HTML/XHTML)
- Added malformed XML declaration detection pattern (2+ consecutive spaces)
- Normalizes malformed declarations to proper single-space format
- Uses elif logic to ensure malformed fix runs before missing declaration check
- Preserves all existing behavior for properly formatted files
Fixes issue where EPUBs passed Python's lenient minidom parser but were rejected
by Amazon's strict validation.1 parent 0746472 commit aea35e2
1 file changed
Lines changed: 25 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
| 235 | + | |
| 236 | + | |
235 | 237 | | |
236 | 238 | | |
237 | 239 | | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
245 | 262 | | |
246 | 263 | | |
247 | 264 | | |
| |||
0 commit comments