Fixes dos line separator issue when reading expression file #1860

This commit is contained in:
Mike Farah 2023-11-10 09:31:29 +11:00
parent b75dc0782b
commit 79a50b9c20
2 changed files with 14 additions and 1 deletions

View File

@ -96,6 +96,17 @@ testBasicExpressionFromFile() {
assertEquals '{"xyz":"meow","cool":"frog"}' "$X" assertEquals '{"xyz":"meow","cool":"frog"}' "$X"
} }
testBasicExpressionFromFileDos() {
./yq -n ".xyz = 123" > test.yml
echo '.xyz = "meow" | .cool = "frog"' | sed 's/$'"/`echo \\\r`/" > instructions.txt
X=$(./yq --from-file instructions.txt test.yml -o=j -I=0)
assertEquals '{"xyz":"meow","cool":"frog"}' "$X"
X=$(./yq ea --from-file instructions.txt test.yml -o=j -I=0)
assertEquals '{"xyz":"meow","cool":"frog"}' "$X"
}
testBasicGitHubAction() { testBasicGitHubAction() {
./yq -n ".a = 123" > test.yml ./yq -n ".a = 123" > test.yml
X=$(cat /dev/null | ./yq test.yml) X=$(cat /dev/null | ./yq test.yml)

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"strings"
"github.com/mikefarah/yq/v4/pkg/yqlib" "github.com/mikefarah/yq/v4/pkg/yqlib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -256,7 +257,8 @@ func processArgs(originalArgs []string) (string, []string, error) {
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
expression = string(expressionBytes) //replace \r\n (windows) with good ol' unix file endings.
expression = strings.ReplaceAll(string(expressionBytes), "\r\n", "\n")
} }
args := processStdInArgs(originalArgs) args := processStdInArgs(originalArgs)