Skip to content

Commit

Permalink
Fixes dos line separator issue when reading expression file #1860
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Nov 9, 2023
1 parent b75dc07 commit 79a50b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions acceptance_tests/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ testBasicExpressionFromFile() {
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() {
./yq -n ".a = 123" > test.yml
X=$(cat /dev/null | ./yq test.yml)
Expand Down
4 changes: 3 additions & 1 deletion cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"strings"

"github.com/mikefarah/yq/v4/pkg/yqlib"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -256,7 +257,8 @@ func processArgs(originalArgs []string) (string, []string, error) {
if err != nil {
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)
Expand Down

0 comments on commit 79a50b9

Please sign in to comment.