-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Description
On Git Bash (MINGW64), Discord bot replies containing Chinese/Unicode characters fail with:
{"message": "The request body contains invalid JSON.", "code": 50109}
Root Cause
In channels/discord.sh, the _discord_api function passes JSON data via curl -d "$data". On Git Bash (MINGW64), the shell expansion of -d "$data" corrupts non-ASCII (Chinese/Unicode) characters in the JSON payload. The same JSON written to a temp file and sent via -d @file works correctly.
Steps to Reproduce
- Install BashClaw on Windows (Git Bash)
- Configure Discord channel
- Send a message to the bot that triggers a Chinese response
- Observe the
invalid JSONerror from Discord API
Fix
Modified _discord_api() POST branch to extract -d data, write it to a temp file, and use -d @tmpfile instead:
POST)
local _post_tmpfile
_post_tmpfile="$(mktemp "${TMPDIR:-/tmp}/bashclaw_post.XXXXXX")"
# Extract -d argument and write to file
local _post_args=()
local _post_data=""
while [[ $# -gt 0 ]]; do
case "$1" in
-d) _post_data="$2"; shift 2 ;;
*) _post_args+=("$1"); shift ;;
esac
done
if [[ -n "$_post_data" ]]; then
printf '%s' "$_post_data" > "$_post_tmpfile"
response="$(curl -sS --max-time 30 \
-X POST \
-H "Authorization: Bot ${token}" \
-H "Content-Type: application/json" \
-d @"$_post_tmpfile" \
"${_post_args[@]}" "$url" 2>/dev/null)"
else
response="$(curl -sS --max-time 30 \
-X POST \
-H "Authorization: Bot ${token}" \
-H "Content-Type: application/json" \
"${_post_args[@]}" "$url" 2>/dev/null)"
fi
rm -f "$_post_tmpfile"
;;Environment
- OS: Windows 11 (Git Bash / MINGW64)
- Bash: 5.2.37
- curl: 8.x (MINGW64 build)
- BashClaw: 1.0.0
Fix: wbw20000@bcbe227
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels