Skip to content
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
2 changes: 1 addition & 1 deletion gitdiff/file_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func hasEpochTimestamp(s string) bool {

// a valid timestamp can have optional ':' in zone specifier
// remove that if it exists so we have a single format
if ts[len(ts)-3] == ':' {
if len(ts) >= 3 && ts[len(ts)-3] == ':' {
ts = ts[:len(ts)-3] + ts[len(ts)-2:]
}

Expand Down
8 changes: 8 additions & 0 deletions gitdiff/file_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,14 @@ func TestHasEpochTimestamp(t *testing.T) {
Input: "+++ file.txt\t2019-03-21 12:34:56.789 -0700\n",
Output: false,
},
"notTimestamp": {
Input: "+++ file.txt\trandom text\n",
Output: false,
},
"notTimestampShort": {
Input: "+++ file.txt\t0\n",
Output: false,
},
}

for name, test := range tests {
Expand Down