kristopolous / TickTick

JSON in your Bash scripts

Home Page:http://9ol.es/TheEmperorsNewClothes.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsing an external json file not working

OlinaRuan opened this issue · comments

When I try to parse an json file, it always complains: "ticktick.sh: line 392: TICKTICK: command not found"

can you please tell me a bit more about this?

JSON:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": ["/usr/include"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        }
    ]
}

build.sh:

#!/usr/bin/env bash
. ticktick.sh
data=`cat ./.vscode/c_cpp_properties.json`
tickParse $data

Returns ticktick.sh: line 424: TICKTICK: command not found

Callstack:
1 - loading ticktick.sh
2 - _tick_fun_tokenize("/home/[...]/build.sh")
3 - Crash on bash -c "$code" -- $ARGV

Variables:
$ARGV=''
$hasError='declare -- hasError="0"'
$code=<contains build.sh>

ok I'll try it out

@kristopolous I've now run into this same thing.

Script:

sh #!/bin/bash . ticktick.sh tickParse `cat /tmp/test.json` tickVars

Input file:

JSON {"string": "stringy!", "int": 7, "array": [ "first", "second" ]}

Output:

``
ticktick.sh: line 424: TICKTICK: command not found
@ Line 6:
string=

``

Thoughts:

Obviously this is a quote containment issue relating to line 18: echo "TICKTICK PARSING ERROR "$1.
I suspect that output is getting picked up in an eval somewhere.

Two errors:

  1. The quoting is not capturing the whole phrase once it gets to that level (maybe echo "\"...$1\""); and
  2. The eval shouldn't be trying to run something that might be error text. Maybe the grep on line 353 is supposed to be preventing this, but because of the quoting it can't?
  3. Third of two: I'm not sure why $1 in the echo is outside the quotes. That seems dangerous.

Okay, so the things I said above are true--that or those error(s) should be fixed, probably before this one since this one shows it/them.
However, the underlying problem here is that for some reason I haven't figured out, tickParse and the function chain it calls, can't handle spaces in the JSON.
If you take the JSON above and remove all spaces, it does not emit the error, or attempt to eval the error message which causes the error.

Maybe there is a problem with one of the regular expressions that __tick_json_tokenize uses? I haven't fully comprehended how that thing is working yet.

This is a very serious bug; I'm creating an issue dedicated to it.

Related: #50