Browse code

builder: avoid decoding "null" string in ADD, COPY and VOLUME step to nil slice

Signed-off-by: Soshi Katsuta <katsuta_soshi@cyberagent.co.jp>

Soshi Katsuta authored on 2015/08/18 02:22:57
Showing 3 changed files
... ...
@@ -232,6 +232,11 @@ func parseString(rest string) (*Node, map[string]bool, error) {
232 232
 
233 233
 // parseJSON converts JSON arrays to an AST.
234 234
 func parseJSON(rest string) (*Node, map[string]bool, error) {
235
+	rest = strings.TrimLeftFunc(rest, unicode.IsSpace)
236
+	if !strings.HasPrefix(rest, "[") {
237
+		return nil, nil, fmt.Errorf("Error parsing \"%s\" as a JSON array", rest)
238
+	}
239
+
235 240
 	var myJSON []interface{}
236 241
 	if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJSON); err != nil {
237 242
 		return nil, nil, err
... ...
@@ -3,6 +3,8 @@ MAINTAINER	Seongyeol Lim <seongyeol37@gmail.com>
3 3
 
4 4
 COPY	.	/go/src/github.com/docker/docker
5 5
 ADD		.	/
6
+ADD		null /
7
+COPY	nullfile /tmp
6 8
 ADD		[ "vimrc", "/tmp" ]
7 9
 COPY	[ "bashrc", "/tmp" ]
8 10
 COPY	[ "test file", "/tmp" ]
... ...
@@ -2,6 +2,8 @@
2 2
 (maintainer "Seongyeol Lim <seongyeol37@gmail.com>")
3 3
 (copy "." "/go/src/github.com/docker/docker")
4 4
 (add "." "/")
5
+(add "null" "/")
6
+(copy "nullfile" "/tmp")
5 7
 (add "vimrc" "/tmp")
6 8
 (copy "bashrc" "/tmp")
7 9
 (copy "test file" "/tmp")