builder: handle certain classes of JSON errors gracefully

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
Erik Hollensbe 2014-08-08 13:44:57 -07:00
parent 4122a981ae
commit 21b15ac920
12 changed files with 15 additions and 3 deletions

View File

@ -91,10 +91,11 @@ func parseJSON(rest string) (*Node, error) {
for _, str := range myJson {
switch str.(type) {
case []interface{}:
return nil, dockerFileErrJSONNesting
case string:
case float64:
str = strconv.FormatFloat(str.(float64), 'G', -1, 64)
default:
return nil, dockerFileErrJSONNesting
}
next.Value = str.(string)
next.Next = blankNode()
@ -115,6 +116,7 @@ func parseMaybeJSON(rest string) (*Node, error) {
if strings.HasPrefix(rest, "[") {
node, err := parseJSON(rest)
if err == nil {
return node, nil
} else if err == dockerFileErrJSONNesting {

View File

@ -37,7 +37,7 @@ func TestTestNegative(t *testing.T) {
_, err = Parse(df)
if err == nil {
t.Fatalf("No error parsing broken dockerfile for %s: %s", dir.Name(), err.Error())
t.Fatalf("No error parsing broken dockerfile for %s", dir.Name())
}
df.Close()

View File

@ -0,0 +1 @@
CMD "[\"echo\", \"Phew, I just managed to escaped those double quotes\"]"

View File

@ -0,0 +1 @@
(cmd "\"[\\\"echo\\\", \\\"Phew, I just managed to escaped those double quotes\\\"]\"")

View File

@ -0,0 +1 @@
CMD '["echo", "Well, JSON in a string is JSON too?"]'

View File

@ -0,0 +1 @@
(cmd "'[\"echo\", \"Well, JSON in a string is JSON too?\"]'")

View File

@ -0,0 +1 @@
CMD ['echo','single quotes are invalid JSON']

View File

@ -0,0 +1 @@
(cmd "['echo','single quotes are invalid JSON']")

View File

@ -0,0 +1 @@
CMD ["echo", "Please, close the brackets when you're done"

View File

@ -0,0 +1 @@
(cmd "[\"echo\", \"Please, close the brackets when you're done\"")

View File

@ -0,0 +1 @@
CMD ["echo", "look ma, no quote!]

View File

@ -0,0 +1 @@
(cmd "[\"echo\", \"look ma, no quote!]")