mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-07 22:42:09 +00:00
Fix builder from being over-aggressive on ${}
`${SOME_VAR%pattern}` was turning into `SOME_VAL%pattern}` which the shell would then balk at.
I've updated the `TOKEN_ENV_INTERPOLATION` regex to account for this (ie, if `${` is used, it _must_ also match the closing `}`), and renamed the variable to not be exported (since it's not used outside the function following it).
I also added comments for the bits of `tokenEnvInterpolation` so they're easier to follow. 😄
Signed-off-by: Andrew Page <admwiggin@gmail.com>
This commit is contained in:
@@ -2710,3 +2710,33 @@ func TestBuildRunShEntrypoint(t *testing.T) {
|
||||
|
||||
logDone("build - entrypoint with /bin/echo running successfully")
|
||||
}
|
||||
|
||||
func TestBuildExoticShellInterpolation(t *testing.T) {
|
||||
name := "testbuildexoticshellinterpolation"
|
||||
defer deleteImages(name)
|
||||
|
||||
_, err := buildImage(name, `
|
||||
FROM busybox
|
||||
|
||||
ENV SOME_VAR a.b.c
|
||||
|
||||
RUN [ "$SOME_VAR" = 'a.b.c' ]
|
||||
RUN [ "${SOME_VAR}" = 'a.b.c' ]
|
||||
RUN [ "${SOME_VAR%.*}" = 'a.b' ]
|
||||
RUN [ "${SOME_VAR%%.*}" = 'a' ]
|
||||
RUN [ "${SOME_VAR#*.}" = 'b.c' ]
|
||||
RUN [ "${SOME_VAR##*.}" = 'c' ]
|
||||
RUN [ "${SOME_VAR/c/d}" = 'a.b.d' ]
|
||||
RUN [ "${#SOME_VAR}" = '5' ]
|
||||
|
||||
RUN [ "${SOME_UNSET_VAR:-$SOME_VAR}" = 'a.b.c' ]
|
||||
RUN [ "${SOME_VAR:+Version: ${SOME_VAR}}" = 'Version: a.b.c' ]
|
||||
RUN [ "${SOME_UNSET_VAR:+${SOME_VAR}}" = '' ]
|
||||
RUN [ "${SOME_UNSET_VAR:-${SOME_VAR:-d.e.f}}" = 'a.b.c' ]
|
||||
`, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
logDone("build - exotic shell interpolation")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user