Fix UTF-8 encoding for foreign characters in ChatGPT responses
Problem
Foreign characters like "è" were being displayed as "Ã" in ChatGPT API responses. This occurred because the VBA code was using responseText which doesn't properly handle UTF-8 encoding from the ChatGPT API.
Root Cause
The ChatGPT API returns responses in UTF-8 encoding, but VBA's responseText property treats the response as Windows-1252/Latin-1. Characters like "è" (UTF-8: 0xC3 0xA8) were being interpreted as two separate bytes, with 0xC3 displaying as "Ã" in Windows-1252.
Solution
Added proper UTF-8 decoding by:
-
New
UTF8ToVBAString()function - Uses ADODB.Stream to convert UTF-8 byte arrays to proper VBA strings -
Modified
GetChatGPTResponse()- Now useshttpRequest.responseBodyinstead ofresponseText - Enhanced error handling - Fallback mechanism if ADODB.Stream is unavailable
- Code quality improvements - Added missing variable declarations
Example
Before: Response containing "café" would display as "café" After: Response properly displays as "café"
Technical Details
- Uses
ADODB.Streamwith UTF-8 charset to properly decode response bytes - Maintains backward compatibility with existing functionality
- Minimal changes (31 lines added, 1 line modified)
- Robust error handling ensures the function works even if ADODB fails
Fixes #2.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
cdn.fwupd.org
- Triggering command:
/usr/bin/fwupdmgr refresh(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.