ycm-core / ycmd

A code-completion & code-comprehension server
https://ycm-core.github.io/ycmd/
GNU General Public License v3.0
1.69k stars 765 forks source link

Wrong request data after transmission #1685

Closed Belserich closed 1 year ago

Belserich commented 1 year ago

I tried getting completions for a file. It works if I trim all control characters off my body, but that kinda defeats the purpose of specifying line_num for the completion. I wrote a minimal working example curl -H "content-type:application/json" -H "x-ycm-hmac:$encoded_hmac" -d "\n" http://localhost:38925/completions

There is a chance my hmac calculation has errors, but it works correctly everytime I send a body with no control characters, so I'm kindly asking if anyone could check that against his own ycmd and tell me if that is indeed a bug or if the problem must be on my end. When I send that, the server prints out b'\\n' as the received body. It proceeds to fail with 'bad hmac'.

I know this isnt a valid body but the server doesnt even get to the content validation.

puremourning commented 1 year ago

Per the specification, all text must be utf-8 encoded, but other than that there is no restriction on including "control characters" in the payload, excepting that it must of course be valid json.

Belserich commented 1 year ago

I found the error, I was using echo to pass around the data in my scripts. It would interpret the control characters before they were passed on. I'm now successfully using printf instead