Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse_env_file discard utf8 bom #2638

Merged
merged 8 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/container/parse_env_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@
return err
}
s := bufio.NewScanner(reader)
firstLine := true
for s.Scan() {
line := s.Text()
if firstLine {
firstLine = false
// skip utf8 bom, powershell 5 legacy uses it for utf8
if len(line) >= 3 && line[0] == 239 && line[1] == 187 && line[2] == 191 {
line = line[3:]
}

Check warning on line 36 in pkg/container/parse_env_file.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/parse_env_file.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}
singleLineEnv := strings.Index(line, "=")
multiLineEnv := strings.Index(line, "<<")
if singleLineEnv != -1 && (multiLineEnv == -1 || singleLineEnv < multiLineEnv) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,16 @@
return err
}
s := bufio.NewScanner(reader)
firstLine := true
for s.Scan() {
line := s.Text()
if firstLine {
firstLine = false
// skip utf8 bom, powershell 5 legacy uses it for utf8
if len(line) >= 3 && line[0] == 239 && line[1] == 187 && line[2] == 191 {
line = line[3:]
}

Check warning on line 531 in pkg/runner/run_context.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/run_context.go#L530-L531

Added lines #L530 - L531 were not covered by tests
}
if len(line) > 0 {
rc.addPath(ctx, line)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ func TestRunEventHostEnvironment(t *testing.T) {
tables = append(tables, []TestJobFileInfo{
{workdir, "windows-prepend-path", "push", "", platforms, secrets},
{workdir, "windows-add-env", "push", "", platforms, secrets},
{workdir, "windows-prepend-path-powershell-5", "push", "", platforms, secrets},
{workdir, "windows-add-env-powershell-5", "push", "", platforms, secrets},
{workdir, "windows-shell-cmd", "push", "", platforms, secrets},
}...)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
runs:
using: composite
steps:
- run: |
echo $env:GITHUB_ENV
echo "kEy=n/a" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
shell: powershell
48 changes: 48 additions & 0 deletions pkg/runner/testdata/windows-add-env-powershell-5/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
on:
push:
jobs:
test:
runs-on: windows-latest
steps:
- run: |
echo $env:GITHUB_ENV
echo "key=val" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "key2<<EOF" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "line1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "line2" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "EOF" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
cat $env:GITHUB_ENV
shell: powershell
- run: |
ls env:
if($env:key -ne 'val') {
echo "Unexpected value for `$env:key: $env:key"
exit 1
}
if($env:key2 -ne "line1`nline2") {
echo "Unexpected value for `$env:key2: $env:key2"
exit 1
}
shell: powershell
- run: |
echo $env:GITHUB_ENV
echo "KEY=test" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8
# Defect missing append, test is broken!!!
echo "Key=expected" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8
shell: powershell
- name: Assert GITHUB_ENV is merged case insensitive
run: exit 1
if: env.KEY != 'expected' || env.Key != 'expected' || env.key != 'expected'
shell: powershell
- name: Assert step env is merged case insensitive
run: exit 1
if: env.KEY != 'n/a' || env.Key != 'n/a' || env.key != 'n/a'
env:
KeY: 'n/a'
shell: powershell
- uses: actions/checkout@v3
- uses: ./windows-add-env-powershell-5/action
- name: Assert composite env is merged case insensitive
run: exit 1
if: env.KEY != 'n/a' || env.Key != 'n/a' || env.key != 'n/a'
shell: powershell
4 changes: 3 additions & 1 deletion pkg/runner/testdata/windows-add-env/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
steps:
- run: |
echo $env:GITHUB_ENV
echo "key=val" > $env:GITHUB_ENV
echo "key=val" >> $env:GITHUB_ENV
echo "key2<<EOF" >> $env:GITHUB_ENV
echo "line1" >> $env:GITHUB_ENV
echo "line2" >> $env:GITHUB_ENV
Expand All @@ -24,7 +24,9 @@ jobs:
}
- run: |
echo $env:GITHUB_ENV
# Defect missing append
echo "KEY=test" > $env:GITHUB_ENV
# Defect missing append, test is broken!!!
echo "Key=expected" > $env:GITHUB_ENV
- name: Assert GITHUB_ENV is merged case insensitive
run: exit 1
Expand Down
34 changes: 34 additions & 0 deletions pkg/runner/testdata/windows-prepend-path-powershell-5/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
defaults:
run:
shell: powershell
jobs:
test:
runs-on: windows-latest
steps:
- run: |
mkdir build
echo '@echo off' | Out-File -FilePath build/test.cmd -Encoding utf8
echo 'echo Hi' | Out-File -FilePath build/test.cmd -Encoding utf8 -Append
mkdir build2
echo '@echo off' | Out-File -FilePath build/test2.cmd -Encoding utf8
echo 'echo test2' | Out-File -FilePath build/test2.cmd -Encoding utf8 -Append
- run: |
echo '${{ tojson(runner) }}'
ls
echo '${{ github.workspace }}'
working-directory: ${{ github.workspace }}\build
- run: |
echo $env:GITHUB_PATH
echo '${{ github.workspace }}\build' | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
cat $env:GITHUB_PATH
- run: |
echo $env:PATH
test
- run: |
echo "PATH=$env:PATH;${{ github.workspace }}\build2" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- run: |
echo $env:PATH
test
test2
Loading