mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-23 00:34:27 +01:00
Add bug fix for presaving history where entries would sometimes end up duplicated
This commit is contained in:
parent
9fcdb7f960
commit
c5a7245991
@ -16,6 +16,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -726,7 +727,11 @@ func parseAtomizedToken(ctx context.Context, token string) (string, interface{},
|
||||
if err != nil {
|
||||
return "", nil, nil, fmt.Errorf("failed to parse start_time:%s as a timestamp: %w", val, err)
|
||||
}
|
||||
return "(CAST(strftime(\"%s\",start_time) AS INTEGER) = ?)", t.Unix(), nil, nil
|
||||
// Note: We are bypassing Gorm's templating here and directly string substituting in the timestamp. This is because
|
||||
// Gorm treats zero and NULL as identical, so if the timestamp we're search for is 0 (aka the beginning of time) then
|
||||
// Gorm will make a query that actually looks for `start_time = NULL`, which will of course never return true. So we
|
||||
// directly template in our string. This is safe from SQL injection since it is just a number.
|
||||
return "(CAST(strftime(\"%s\",start_time) AS INTEGER) = " + strconv.FormatInt(t.Unix(), 10) + ")", nil, nil, nil
|
||||
case "end_time":
|
||||
// Note that this atom probably isn't useful for interactive usage since it does exact matching, but we use it
|
||||
// internally for pre-saving history entries.
|
||||
@ -734,7 +739,8 @@ func parseAtomizedToken(ctx context.Context, token string) (string, interface{},
|
||||
if err != nil {
|
||||
return "", nil, nil, fmt.Errorf("failed to parse end_time:%s as a timestamp: %w", val, err)
|
||||
}
|
||||
return "(CAST(strftime(\"%s\",end_time) AS INTEGER) = ?)", t.Unix(), nil, nil
|
||||
// See note above about why we're directly templating in here rather than using parameterized queries
|
||||
return "(CAST(strftime(\"%s\",end_time) AS INTEGER) = " + strconv.FormatInt(t.Unix(), 10) + ")", nil, nil, nil
|
||||
case "command":
|
||||
return "(instr(command, ?) > 0)", val, nil, nil
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user