Skip to content

Commit

Permalink
parse checksum even when no EOL is found (#285)
Browse files Browse the repository at this point in the history
In case a checksum file does not end with '\n', the checksum can still
be valid. When hitting EOF, verify that the read line is non-empty, and
continue with parsing.
  • Loading branch information
nixpanic authored Oct 20, 2020
1 parent 0f941aa commit 3d7b883
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ func (c *Client) ChecksumFromFile(checksumFile string, src *url.URL) (*FileCheck
return nil, fmt.Errorf(
"Error reading checksum file: %s", err)
}
break
if line == "" {
break
}
// parse the line, if we hit EOF, but the line is not empty
}
checksum, err := parseChecksumLine(line)
if err != nil || checksum == nil {
Expand Down
6 changes: 6 additions & 0 deletions get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ func TestGetFile_checksum_from_file(t *testing.T) {
true,
false,
},
{
// checksum file does not have EOL, ends line with EOF
"?checksum=file:" + httpChecksums.URL + "/sha512-p-EOF.sum",
true,
false,
},
}

for _, tc := range cases {
Expand Down
1 change: 1 addition & 0 deletions testdata/checksum-file/sha512-p-EOF.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
060a8cc41c501e41b4537029661090597aeb4366702ac3cae8959f24b2c49005d6bd339833ebbeb481b127ac822d70b937c1637c8d0eaf81b6979d4c1d75d0e1

0 comments on commit 3d7b883

Please sign in to comment.