From dfd396b480a2860d4424baeab82384fe95a23015 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Thu, 23 Jun 2022 14:31:04 +1000 Subject: [PATCH] When split expression includes an extension, dont add .yml automatically --- .gitignore | 1 + acceptance_tests/split-printer.sh | 25 +++++++++++++++++++++++++ pkg/yqlib/printer_writer.go | 6 +++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0c2a0b48..53a1f625 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ yq*.snap test.yml test*.yml +test*.yaml 0.yml 1.yml 2.yml diff --git a/acceptance_tests/split-printer.sh b/acceptance_tests/split-printer.sh index a8e81a91..4629c496 100755 --- a/acceptance_tests/split-printer.sh +++ b/acceptance_tests/split-printer.sh @@ -25,6 +25,31 @@ EOM assertEquals "$expectedDoc2" "$doc2" } +testBasicSplitWithNameCustomExtension() { + rm test*.yaml || true + cat >test.yml <test.yml < 0 { name = result.MatchingNodes.Front().Value.(*CandidateNode).Node.Value } - name = fmt.Sprintf("%v.%v", name, sp.extension) + var extensionRegexp = regexp.MustCompile(`\.[a-zA-Z0-9]+$`) + if !extensionRegexp.MatchString(name) { + name = fmt.Sprintf("%v.%v", name, sp.extension) + } f, err := os.Create(name)