Use default token for parsing

This commit is contained in:
Priya Wadhwa
2018-03-27 09:44:51 -07:00
parent f6139f249a
commit b64f23b078
5 changed files with 10 additions and 35 deletions
+5 -10
View File
@@ -17,7 +17,6 @@ limitations under the License.
package util
import (
"bytes"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/docker/docker/builder/dockerfile/parser"
"github.com/docker/docker/builder/dockerfile/shell"
@@ -29,10 +28,10 @@ import (
)
// ResolveEnvironmentReplacement resolves a list of values by calling resolveEnvironmentReplacement
func ResolveEnvironmentReplacementList(command string, values, envs []string, isFilepath bool) ([]string, error) {
func ResolveEnvironmentReplacementList(values, envs []string, isFilepath bool) ([]string, error) {
var resolvedValues []string
for _, value := range values {
resolved, err := ResolveEnvironmentReplacement(command, value, envs, isFilepath)
resolved, err := ResolveEnvironmentReplacement(value, envs, isFilepath)
logrus.Debugf("Resolved %s to %s", value, resolved)
if err != nil {
return nil, err
@@ -42,7 +41,7 @@ func ResolveEnvironmentReplacementList(command string, values, envs []string, is
return resolvedValues, nil
}
// resolveEnvironmentReplacement resolves replacing env variables in some text from envs
// ResolveEnvironmentReplacement resolves replacing env variables in some text from envs
// It takes in a string representation of the command, the value to be resolved, and a list of envs (config.Env)
// Ex: fp = $foo/newdir, envs = [foo=/foodir], then this should return /foodir/newdir
// The dockerfile/shell package handles processing env values
@@ -51,12 +50,8 @@ func ResolveEnvironmentReplacementList(command string, values, envs []string, is
// ""a'b'c"" -> "a'b'c"
// "Rex\ The\ Dog \" -> "Rex The Dog"
// "a\"b" -> "a"b"
func ResolveEnvironmentReplacement(command, value string, envs []string, isFilepath bool) (string, error) {
p, err := parser.Parse(bytes.NewReader([]byte(command)))
if err != nil {
return "", err
}
shlex := shell.NewLex(p.EscapeToken)
func ResolveEnvironmentReplacement(value string, envs []string, isFilepath bool) (string, error) {
shlex := shell.NewLex(parser.DefaultEscapeToken)
fp, err := shlex.ProcessWord(value, envs)
if !isFilepath {
return fp, err