builder: handle certain classes of JSON errors gracefully
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh) Upstream-commit: 21b15ac920d5e51f636d7febf07a4a52f5e61bff Component: engine
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
CMD "[\"echo\", \"Phew, I just managed to escaped those double quotes\"]"
|
||||
+1
@@ -0,0 +1 @@
|
||||
(cmd "\"[\\\"echo\\\", \\\"Phew, I just managed to escaped those double quotes\\\"]\"")
|
||||
+1
@@ -0,0 +1 @@
|
||||
CMD '["echo", "Well, JSON in a string is JSON too?"]'
|
||||
+1
@@ -0,0 +1 @@
|
||||
(cmd "'[\"echo\", \"Well, JSON in a string is JSON too?\"]'")
|
||||
+1
@@ -0,0 +1 @@
|
||||
CMD ['echo','single quotes are invalid JSON']
|
||||
@@ -0,0 +1 @@
|
||||
(cmd "['echo','single quotes are invalid JSON']")
|
||||
+1
@@ -0,0 +1 @@
|
||||
CMD ["echo", "Please, close the brackets when you're done"
|
||||
+1
@@ -0,0 +1 @@
|
||||
(cmd "[\"echo\", \"Please, close the brackets when you're done\"")
|
||||
+1
@@ -0,0 +1 @@
|
||||
CMD ["echo", "look ma, no quote!]
|
||||
+1
@@ -0,0 +1 @@
|
||||
(cmd "[\"echo\", \"look ma, no quote!]")
|
||||
Reference in New Issue
Block a user