Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Golden files are embedded and compared byte-for-byte against logger output,
# so they must keep LF line endings on checkout (Windows defaults to CRLF).
*.golden text eol=lf
*.txtar text eol=lf
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
uses: github/codeql-action/init@v4
with:
languages: go

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
uses: github/codeql-action/analyze@v4
15 changes: 9 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,33 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.23.x, 1.22.x] # when updating versions, update it below too.
go: [1.25.x, 1.26.x] # when updating versions, update it below too.
runs-on: ${{ matrix.os }}
name: Test
steps:

- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}

- name: Check out code
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Test
# TODO(henvic): Skip generating code coverage when not sending it to Coveralls to speed up testing.
if: ${{ matrix.os != 'ubuntu-latest' || matrix.go != '1.26.x' }}
run: go test -race ./...

- name: Test with code coverage
if: ${{ matrix.os == 'ubuntu-latest' && matrix.go == '1.26.x' }}
# Remove example directory from code coverage explicitly since after #26 it
# started being considered on the code coverage report and we don't want that.
continue-on-error: ${{ matrix.os != 'ubuntu-latest' || matrix.go != '1.23.x' }}
run: |
go test -race -covermode atomic -coverprofile=profile.cov ./...
sed -i '/^github\.com\/henvic\/httpretty\/example\//d' profile.cov

- name: Code coverage
if: ${{ matrix.os == 'ubuntu-latest' && matrix.go == '1.23.x' }}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.go == '1.26.x' }}
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: "1.23.x"
go-version: "1.26.x"

- name: Check out code
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Verify dependencies
run: |
Expand Down
15 changes: 15 additions & 0 deletions binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ func TestIsBinary(t *testing.T) {
data: bytes.Repeat([]byte{1, 2, 3, 4, 5, 6, 7, 8}, 65),
binary: true,
},
{
desc: "Binary header (exactly 512 bytes) with text trailer",
data: append(bytes.Repeat([]byte{1, 2, 3, 4, 5, 6, 7, 8}, 64), []byte("plain text trailer")...),
binary: true,
},
{
desc: "Text over 512 bytes with binary trailer",
data: append(bytes.Repeat([]byte("plain text "), 50), []byte{1, 2, 3, 4, 5}...),
binary: false,
},
{
desc: "Large text with leading UTF-8 BOM and binary trailer", // https://www.unicode.org/faq/utf_bom#BOM
data: append(append([]byte("\xEF\xBB\xBF"), bytes.Repeat([]byte("plain text "), 50)...), []byte{1, 2, 3, 4, 5}...),
binary: false,
},
{
desc: "JPEG image",
data: []byte("\xFF\xD8\xFF"),
Expand Down
Loading
Loading