github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/builder/dockerfile/instructions/errors_windows.go (about) 1 package instructions 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "regexp" 7 "strings" 8 ) 9 10 func errNotJSON(command, original string) error { 11 // For Windows users, give a hint if it looks like it might contain 12 // a path which hasn't been escaped such as ["c:\windows\system32\prog.exe", "-param"], 13 // as JSON must be escaped. Unfortunate... 14 // 15 // Specifically looking for quote-driveletter-colon-backslash, there's no 16 // double backslash and a [] pair. No, this is not perfect, but it doesn't 17 // have to be. It's simply a hint to make life a little easier. 18 extra := "" 19 original = filepath.FromSlash(strings.ToLower(strings.Replace(strings.ToLower(original), strings.ToLower(command)+" ", "", -1))) 20 if len(regexp.MustCompile(`"[a-z]:\\.*`).FindStringSubmatch(original)) > 0 && 21 !strings.Contains(original, `\\`) && 22 strings.Contains(original, "[") && 23 strings.Contains(original, "]") { 24 extra = fmt.Sprintf(`. It looks like '%s' includes a file path without an escaped back-slash. JSON requires back-slashes to be escaped such as ["c:\\path\\to\\file.exe", "/parameter"]`, original) 25 } 26 return fmt.Errorf("%s requires the arguments to be in JSON form%s", command, extra) 27 }