mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
parent
4122a981ae
commit
21b15ac920
12 changed files with 15 additions and 3 deletions
|
@ -91,10 +91,11 @@ func parseJSON(rest string) (*Node, error) {
|
||||||
|
|
||||||
for _, str := range myJson {
|
for _, str := range myJson {
|
||||||
switch str.(type) {
|
switch str.(type) {
|
||||||
case []interface{}:
|
case string:
|
||||||
return nil, dockerFileErrJSONNesting
|
|
||||||
case float64:
|
case float64:
|
||||||
str = strconv.FormatFloat(str.(float64), 'G', -1, 64)
|
str = strconv.FormatFloat(str.(float64), 'G', -1, 64)
|
||||||
|
default:
|
||||||
|
return nil, dockerFileErrJSONNesting
|
||||||
}
|
}
|
||||||
next.Value = str.(string)
|
next.Value = str.(string)
|
||||||
next.Next = blankNode()
|
next.Next = blankNode()
|
||||||
|
@ -115,6 +116,7 @@ func parseMaybeJSON(rest string) (*Node, error) {
|
||||||
|
|
||||||
if strings.HasPrefix(rest, "[") {
|
if strings.HasPrefix(rest, "[") {
|
||||||
node, err := parseJSON(rest)
|
node, err := parseJSON(rest)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return node, nil
|
return node, nil
|
||||||
} else if err == dockerFileErrJSONNesting {
|
} else if err == dockerFileErrJSONNesting {
|
||||||
|
|
|
@ -37,7 +37,7 @@ func TestTestNegative(t *testing.T) {
|
||||||
|
|
||||||
_, err = Parse(df)
|
_, err = Parse(df)
|
||||||
if err == nil {
|
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()
|
df.Close()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
CMD "[\"echo\", \"Phew, I just managed to escaped those double quotes\"]"
|
|
@ -0,0 +1 @@
|
||||||
|
(cmd "\"[\\\"echo\\\", \\\"Phew, I just managed to escaped those double quotes\\\"]\"")
|
|
@ -0,0 +1 @@
|
||||||
|
CMD '["echo", "Well, JSON in a string is JSON too?"]'
|
|
@ -0,0 +1 @@
|
||||||
|
(cmd "'[\"echo\", \"Well, JSON in a string is JSON too?\"]'")
|
|
@ -0,0 +1 @@
|
||||||
|
CMD ['echo','single quotes are invalid JSON']
|
|
@ -0,0 +1 @@
|
||||||
|
(cmd "['echo','single quotes are invalid JSON']")
|
|
@ -0,0 +1 @@
|
||||||
|
CMD ["echo", "Please, close the brackets when you're done"
|
|
@ -0,0 +1 @@
|
||||||
|
(cmd "[\"echo\", \"Please, close the brackets when you're done\"")
|
|
@ -0,0 +1 @@
|
||||||
|
CMD ["echo", "look ma, no quote!]
|
|
@ -0,0 +1 @@
|
||||||
|
(cmd "[\"echo\", \"look ma, no quote!]")
|
Loading…
Reference in a new issue