Skip to content

Fix smart quotes handling in SitemapNode.__repr__()#258

Merged
goodtune merged 4 commits intomainfrom
copilot/fix-smart-quotes-in-sitemapnode
Jan 31, 2026
Merged

Fix smart quotes handling in SitemapNode.__repr__()#258
goodtune merged 4 commits intomainfrom
copilot/fix-smart-quotes-in-sitemapnode

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Fix Unicode Smart Quotes in SitemapNode.__repr__()

The issue: SitemapNode.__repr__() fails when the title contains Unicode characters like smart quotes (e.g., " ", ' '), causing DjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xe2.

Changes Made:

  • Modified SitemapNode.__repr__() in touchtechnology/common/models.py to use f-strings and ascii() function
  • Added comprehensive test test_repr_with_unicode_smart_quotes using assertEqual with exact expected value
  • Added test test_logging_with_unicode_title_in_repr using assertCountEqual for exact log verification
  • Removed unused import logging statement from test
  • All 97 tests in touchtechnology.common module pass
  • All 5 tests in touchtechnology.content module pass (which uses repr in middleware)
  • CodeQL security scan passed with 0 alerts
  • Addressed all PR review feedback

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.

Copilot AI and others added 2 commits January 31, 2026 02:16
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
Copilot AI requested a review from goodtune January 31, 2026 02:21
…rtCountEqual for logs, remove unused import

Co-authored-by: goodtune <286798+goodtune@users.noreply.github.com>
@goodtune goodtune changed the title Fix UnicodeDecodeError in SitemapNode.__repr__() with non-ASCII titles Fix UnicodeDecodeError in SitemapNode.__repr__() with non-ASCII titles Jan 31, 2026
@goodtune goodtune changed the title Fix UnicodeDecodeError in SitemapNode.__repr__() with non-ASCII titles Fix smart quotes handling in SitemapNode.__repr__() Jan 31, 2026
@goodtune goodtune marked this pull request as ready for review January 31, 2026 03:41
@goodtune goodtune merged commit 90eb0e4 into main Jan 31, 2026
16 checks passed
@goodtune goodtune deleted the copilot/fix-smart-quotes-in-sitemapnode branch January 31, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use of ‘smart quotes’ in SitemapNode.title breaks touchtechnology.admin

2 participants