git-for-windows / git

A fork of Git containing Windows-specific patches.
http://gitforwindows.org/
Other
8.37k stars 2.54k forks source link

Sending requests with Chinese characters using curl will fail:Invalid UTF-8 middle byte 0xce #4858

Open leevin101 opened 7 months ago

leevin101 commented 7 months ago

Setup

$ git --version --build-options

** 
git version 2.33.0.windows.2
cpu: x86_64
built from commit: 8735530946cced809cc6cc4c2ca3b078cdb3dfc8
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
**

windows 10 64-bit

$ cmd.exe /c ver

** Microsoft Windows [版本 10.0.19045.4046] **
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
> type "$env:USERPROFILE\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

Editor Option: Notepad++
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Merge
Use Credential Manager: Core
Performance Tweaks FSCache: Enabled
Enable Symlinks: Enabled
Enable Pseudo Console Support: Enabled
Enable FSMonitor: Enabled

insert your response here

Details

when use curl comman with Chinese charter,will response with exception

curl 'http://192.168.56.1:9200/_xpack/sql'  -H 'Content-Type: application/json' -d'{"query":"select * from test where name ='\''张三'\'' "}'
{"columns":[{"name":"name","type":"keyword"},{"name":"create_time","type":"keyword"}],"rows":[["张三","2023-06-05 13:37:45"]
]}
{
  "error" : {
    "root_cause" : [
      {
        "type" : "x_content_parse_exception",
        "reason" : "[1:10] [sql/query] failed to parse field [query]"
      }
    ],
    "type" : "x_content_parse_exception",
    "reason" : "[1:10] [sql/query] failed to parse field [query]",
    "caused_by" : {
      "type" : "json_parse_exception",
      "reason" : "Invalid UTF-8 middle byte 0xce\n at [Source: (org.elasticsearch.common.io.stream.InputStreamStreamInput); line: 1, column: 87]"
    }
  },
  "status" : 400
}

NO

dscho commented 7 months ago
  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

when use curl comman with Chinese charter,will response with exception

Sure, but that was not the question. The question was Bash or CMD or PowerShell or other.

Also keep in mind that curl is not exactly within Git for Windows' area of support.

Having said that, you may need to set LC_CTYPE=C.UTF-8 or something similar to make that command work correctly; Unlike Git for Windows, the curl.exe does not assume UTF-8 encoding in its input.

leevin101 commented 7 months ago

thanks for your reply. But I found that a few curl. exe versions with the word "Unicode" in the Feature can successfully execute. image

image