Skip to content

Bug: curl -d corrupts Chinese/Unicode JSON on Git Bash (MINGW64) #6

@wbw20000

Description

@wbw20000

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

  1. Install BashClaw on Windows (Git Bash)
  2. Configure Discord channel
  3. Send a message to the bot that triggers a Chinese response
  4. Observe the invalid JSON error 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions