Skip to content

Commit 3d7b883

Browse files
authored
parse checksum even when no EOL is found (#285)
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.
1 parent 0f941aa commit 3d7b883

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

checksum.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ func (c *Client) ChecksumFromFile(checksumFile string, src *url.URL) (*FileCheck
259259
return nil, fmt.Errorf(
260260
"Error reading checksum file: %s", err)
261261
}
262-
break
262+
if line == "" {
263+
break
264+
}
265+
// parse the line, if we hit EOF, but the line is not empty
263266
}
264267
checksum, err := parseChecksumLine(line)
265268
if err != nil || checksum == nil {

get_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ func TestGetFile_checksum_from_file(t *testing.T) {
427427
true,
428428
false,
429429
},
430+
{
431+
// checksum file does not have EOL, ends line with EOF
432+
"?checksum=file:" + httpChecksums.URL + "/sha512-p-EOF.sum",
433+
true,
434+
false,
435+
},
430436
}
431437

432438
for _, tc := range cases {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
060a8cc41c501e41b4537029661090597aeb4366702ac3cae8959f24b2c49005d6bd339833ebbeb481b127ac822d70b937c1637c8d0eaf81b6979d4c1d75d0e1

0 commit comments

Comments
 (0)