Red5d / pushbullet-bash

Bash interface to the PushBullet API
236 stars 41 forks source link

Pushing notes with newlines causes a JSON decode error #50

Closed glutanimate closed 8 years ago

glutanimate commented 8 years ago

Steps to reproduce:

  1. Create a variable with newlines within:

    var=$'a\nb\nc'
  2. Try to push it:

    pushbullet push device note title "$var"
  3. This will fail with the following message:

    Error submitting the request. The error message was: {"error":{"type":"invalid_request","message":"Failed to decode JSON body.","cat":"(=^‥^=)"}}

I first ran into this issue after updating to the latest commits that overhauled the push system. I hope someone can find a way to fix this as supporting newlines is quite important for longer passages of text.

Thanks a lot for reading this.

Red5d commented 8 years ago

That's a strange way to create a variable...

Pushing this variable with newlines works for me:

var="line1\nline2\nline3"

pushbullet push device note title "$var"
glutanimate commented 8 years ago

Those aren't actual newlines, though; They are escape sequences that are recognized as newlines under certain circumstances (e.g. echo -e).

See for yourself:

var1="line1\nline2\nline3"
var2=$'line1\nline2\nline3'
echo "$var1"
echo "$var2"
echo -e "$var1"

More info on this here:

https://stackoverflow.com/questions/9139401/trying-to-embed-newline-in-a-variable-in-bash

A more compatible way to insert newlines would be to simply type them into the terminal:

var="a
b
c"

But this is harder to copy and paste correctly, so I went with the bashism above.

glutanimate commented 8 years ago

I've filed a pull-request with a few modifications to the script that have fixed this for me (#51). Newlines in the body of pushes should be handled fine now.

Red5d commented 8 years ago

Ok, well if that fixes it for you, great. I've accepted the pull request.