Fix smart quotes handling in SitemapNode.__repr__()#258
Merged
Conversation
Co-authored-by: goodtune <286798+goodtune@users.noreply.github.com>
…ve test naming Co-authored-by: goodtune <286798+goodtune@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix use of smart quotes in SitemapNode.title
Fix UnicodeDecodeError in SitemapNode.__repr__() with non-ASCII titles
Jan 31, 2026
goodtune
reviewed
Jan 31, 2026
…rtCountEqual for logs, remove unused import Co-authored-by: goodtune <286798+goodtune@users.noreply.github.com>
UnicodeDecodeError in SitemapNode.__repr__() with non-ASCII titles
UnicodeDecodeError in SitemapNode.__repr__() with non-ASCII titlesSitemapNode.__repr__()
goodtune
approved these changes
Jan 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Unicode Smart Quotes in
SitemapNode.__repr__()The issue:
SitemapNode.__repr__()fails when the title contains Unicode characters like smart quotes (e.g., " ", ' '), causingDjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xe2.Changes Made:
SitemapNode.__repr__()intouchtechnology/common/models.pyto use f-strings andascii()functiontest_repr_with_unicode_smart_quotesusingassertEqualwith exact expected valuetest_logging_with_unicode_title_in_reprusingassertCountEqualfor exact log verificationimport loggingstatement from testtouchtechnology.commonmodule passtouchtechnology.contentmodule pass (which uses repr in middleware)Technical Details:
The fix uses Python's
ascii()built-in function which converts any Unicode string to an ASCII-safe representation by escaping non-ASCII characters. Now using modern f-strings for cleaner code. For example, smart quotes like " (U+201C) become\u201c. This ensures that__repr__()always returns an ASCII-only string, preventing encoding errors in logging, debugging, and string formatting contexts.Security Summary:
No security vulnerabilities introduced or discovered. CodeQL scan passed with 0 alerts.