From 01267d062b9c26affc9083d42dd965e7ee5e9032 Mon Sep 17 00:00:00 2001 From: Daniel Vystrcil <31454345+da6d6i7-bronga@users.noreply.github.com> Date: Wed, 9 Jun 2021 16:59:30 -0700 Subject: [PATCH 1/5] Update Dockerfile Alpine 3.15.5 has fixes for CVE-2021-30139, CVE-2021-28831, CVE-2021-23840, and CVE-2021-3450 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f4b0622e..6ef42cc0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN CGO_ENABLED=0 make local build # Choose alpine as a base image to make this useful for CI, as many # CI tools expect an interactive shell inside the container -FROM alpine:3.12.3 as production +FROM alpine:3.13.5 as production COPY --from=builder /go/src/mikefarah/yq/yq /usr/bin/yq RUN chmod +x /usr/bin/yq From 88bee2809f85a8697d18800974b42af4daa070b6 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 11 Jun 2021 14:27:44 +1000 Subject: [PATCH 2/5] Fixed issue on creating objects using [] --- pkg/yqlib/operator_equals_test.go | 4 ++-- pkg/yqlib/operator_traverse_path.go | 9 ++++++++- pkg/yqlib/operator_traverse_path_test.go | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/yqlib/operator_equals_test.go b/pkg/yqlib/operator_equals_test.go index 6b7f2aa0..06fd7811 100644 --- a/pkg/yqlib/operator_equals_test.go +++ b/pkg/yqlib/operator_equals_test.go @@ -14,7 +14,7 @@ var equalsOperatorScenarios = []expressionScenario{ }, { skipDoc: true, - document: `a: cat`, + document: `a: cat`, expression: ".a == .b", expected: []string{ "D0, P[a], (!!bool)::false\n", @@ -22,7 +22,7 @@ var equalsOperatorScenarios = []expressionScenario{ }, { skipDoc: true, - document: `a: cat`, + document: `a: cat`, expression: ".b == .a", expected: []string{ "D0, P[a], (!!bool)::false\n", diff --git a/pkg/yqlib/operator_traverse_path.go b/pkg/yqlib/operator_traverse_path.go index 98ba5356..d87b0e20 100644 --- a/pkg/yqlib/operator_traverse_path.go +++ b/pkg/yqlib/operator_traverse_path.go @@ -127,9 +127,16 @@ func traverseArrayIndices(context Context, matchingNode *CandidateNode, indicesT node := matchingNode.Node if node.Tag == "!!null" { log.Debugf("OperatorArrayTraverse got a null - turning it into an empty array") - // auto vivification, make it into an empty array + // auto vivification node.Tag = "" node.Kind = yaml.SequenceNode + //check that the indices are numeric, if not, then we should create an object + if len(indicesToTraverse) != 0 { + _, err := strconv.ParseInt(indicesToTraverse[0].Value, 10, 64) + if err != nil { + node.Kind = yaml.MappingNode + } + } } if node.Kind == yaml.AliasNode { diff --git a/pkg/yqlib/operator_traverse_path_test.go b/pkg/yqlib/operator_traverse_path_test.go index dd917fd4..9e230915 100644 --- a/pkg/yqlib/operator_traverse_path_test.go +++ b/pkg/yqlib/operator_traverse_path_test.go @@ -43,6 +43,13 @@ var traversePathOperatorScenarios = []expressionScenario{ "D0, P[0 0 0], (!!int)::1\n", }, }, + { + skipDoc: true, + expression: `.["cat"] = "thing"`, + expected: []string{ + "D0, P[], ()::cat: thing\n", + }, + }, { description: "Simple map navigation", document: `{a: {b: apple}}`, From da47318f426522701f576c72c7e1053f1dfa92fb Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 12 Jun 2021 08:26:27 +1000 Subject: [PATCH 3/5] Fixed newline issue https://github.com/mikefarah/yq/issues/855 --- pkg/yqlib/expression_processing_test.go | 13 +++++++++++++ pkg/yqlib/expression_tokeniser.go | 2 +- pkg/yqlib/operator_traverse_path_test.go | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/expression_processing_test.go b/pkg/yqlib/expression_processing_test.go index 2b2f7060..0af22b9f 100644 --- a/pkg/yqlib/expression_processing_test.go +++ b/pkg/yqlib/expression_processing_test.go @@ -7,11 +7,24 @@ import ( "github.com/mikefarah/yq/v4/test" ) +var variableWithNewLine = `"cat +"` + var pathTests = []struct { path string expectedTokens []interface{} expectedPostFix []interface{} }{ + { + ".a\n", + append(make([]interface{}, 0), "a"), + append(make([]interface{}, 0), "a"), + }, + { + variableWithNewLine, + append(make([]interface{}, 0), "cat\n (string)"), + append(make([]interface{}, 0), "cat\n (string)"), + }, { `.[0]`, append(make([]interface{}, 0), "SELF", "TRAVERSE_ARRAY", "[", "0 (int64)", "]"), diff --git a/pkg/yqlib/expression_tokeniser.go b/pkg/yqlib/expression_tokeniser.go index 0018489b..85e64375 100644 --- a/pkg/yqlib/expression_tokeniser.go +++ b/pkg/yqlib/expression_tokeniser.go @@ -320,7 +320,7 @@ func initLexer() (*lex.Lexer, error) { lexer.Add([]byte("( |\t|\n|\r)+"), skip) lexer.Add([]byte(`\."[^ "]+"\??`), pathToken(true)) - lexer.Add([]byte(`\.[^ \}\{\:\[\],\|\.\[\(\)=]+\??`), pathToken(false)) + lexer.Add([]byte(`\.[^ \}\{\:\[\],\|\.\[\(\)=\n]+\??`), pathToken(false)) lexer.Add([]byte(`\.`), selfToken()) lexer.Add([]byte(`\|`), opToken(pipeOpType)) diff --git a/pkg/yqlib/operator_traverse_path_test.go b/pkg/yqlib/operator_traverse_path_test.go index 9e230915..59fddde3 100644 --- a/pkg/yqlib/operator_traverse_path_test.go +++ b/pkg/yqlib/operator_traverse_path_test.go @@ -35,6 +35,14 @@ var traversePathOperatorScenarios = []expressionScenario{ "D0, P[0 0], (!!int)::1\n", }, }, + { + skipDoc: true, + document: `b: cat`, + expression: ".b\n", + expected: []string{ + "D0, P[b], (!!str)::cat\n", + }, + }, { skipDoc: true, document: `[[[1]]]`, From 9e61f88dba1391539377f284285130e4896ce0a0 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sat, 12 Jun 2021 08:18:56 +1000 Subject: [PATCH 4/5] Add darwin/arm64 builds --- scripts/xcompile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/xcompile.sh b/scripts/xcompile.sh index 4c71eacf..449de054 100755 --- a/scripts/xcompile.sh +++ b/scripts/xcompile.sh @@ -4,7 +4,7 @@ set -e # at https://github.com/inconshreveable/gonative -CGO_ENABLED=0 gox -ldflags "${LDFLAGS}" -output="build/yq_{{.OS}}_{{.Arch}}" --osarch="darwin/amd64 freebsd/386 freebsd/amd64 freebsd/arm linux/386 linux/amd64 linux/arm linux/arm64 linux/mips linux/mips64 linux/mips64le linux/mipsle linux/ppc64 linux/ppc64le linux/s390x netbsd/386 netbsd/amd64 netbsd/arm openbsd/386 openbsd/amd64 windows/386 windows/amd64" +CGO_ENABLED=0 gox -ldflags "${LDFLAGS}" -output="build/yq_{{.OS}}_{{.Arch}}" --osarch="darwin/amd64 darwin/arm64 freebsd/386 freebsd/amd64 freebsd/arm linux/386 linux/amd64 linux/arm linux/arm64 linux/mips linux/mips64 linux/mips64le linux/mipsle linux/ppc64 linux/ppc64le linux/s390x netbsd/386 netbsd/amd64 netbsd/arm openbsd/386 openbsd/amd64 windows/386 windows/amd64" cd build rhash -r -a . -o checksums @@ -21,4 +21,4 @@ rm yq_windows_386.exe.tar.gz rm yq_windows_amd64.exe.tar.gz zip yq_windows_386.zip yq_windows_386.exe -zip yq_windows_amd64.zip yq_windows_amd64.exe \ No newline at end of file +zip yq_windows_amd64.zip yq_windows_amd64.exe From 4bb2d04d437170e32b31cf399f4a3ead3de404a0 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 12 Jun 2021 16:40:42 +1000 Subject: [PATCH 5/5] Increment version --- cmd/version.go | 2 +- github-action/Dockerfile | 2 +- snap/snapcraft.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 4e954c83..ca0cbe33 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -11,7 +11,7 @@ var ( GitDescribe string // Version is main version number that is being run at the moment. - Version = "4.9.5" + Version = "4.9.6" // VersionPrerelease is a pre-release marker for the version. If this is "" (empty string) // then it means that it is a final release. Otherwise, this is a pre-release diff --git a/github-action/Dockerfile b/github-action/Dockerfile index 4a47ef68..2783bd81 100644 --- a/github-action/Dockerfile +++ b/github-action/Dockerfile @@ -1,4 +1,4 @@ -FROM mikefarah/yq:4.9.5 +FROM mikefarah/yq:4.9.6 COPY entrypoint.sh /entrypoint.sh diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index b8a257d5..2a9f9741 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: yq -version: '4.9.5' +version: '4.9.6' summary: A lightweight and portable command-line YAML processor description: | The aim of the project is to be the jq or sed of yaml files.