Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Conversation

Copy link

Copilot AI commented May 23, 2025

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:

  1. New UTF8ToVBAString() function - Uses ADODB.Stream to convert UTF-8 byte arrays to proper VBA strings
  2. Modified GetChatGPTResponse() - Now uses httpRequest.responseBody instead of responseText
  3. Enhanced error handling - Fallback mechanism if ADODB.Stream is unavailable
  4. 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.Stream with 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:


💡 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.

Co-authored-by: jddev273 <59052623+jddev273@users.noreply.github.com>
Copilot AI changed the title [WIP] Not handling foreign characters properly Fix UTF-8 encoding for foreign characters in ChatGPT responses May 23, 2025
Copilot AI requested a review from jddev273 May 23, 2025 19:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not handling foreign characters properly

2 participants