diff options
author | Robin Jarry <robin@jarry.cc> | 2022-11-23 01:04:48 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-11-24 20:14:08 +0100 |
commit | eebb85a9d5bd35b460d5cf89a0cadcfce5b68137 (patch) | |
tree | 3e6932f7a0c66ef15a357d62c8d75ffa332ae55d | |
parent | 4db1353d97552b60ff57cbd6987fbe9dc6e6724b (diff) | |
download | aerc-eebb85a9d5bd35b460d5cf89a0cadcfce5b68137.tar.gz |
config: fix [filters] ordering
Using KeysHash() does not guarantee any stable ordering of elements.
This causes random weirdness when some filters are using wildcards:
[filters]
text/plain=colorize
text/html=html
text/*=bat -fP --file-name="$AERC_FILENAME" --style=plain
When the source order is not preserved, the text/* filter may be matched
first against text/plain or text/html parts.
Use Keys() which does not create a map and preserve original ordering.
Fixes: 17bb9387c4a3 ("config: move [filters] parsing to separate file")
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
-rw-r--r-- | config/filters.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/config/filters.go b/config/filters.go index c3d10f68..ffa203f9 100644 --- a/config/filters.go +++ b/config/filters.go @@ -29,14 +29,13 @@ func (config *AercConfig) parseFilters(file *ini.File) error { goto end } - // TODO: Parse the filter more finely, e.g. parse the regex - for match, cmd := range filters.KeysHash() { + for _, key := range filters.Keys() { filter := FilterConfig{ - Command: cmd, - Filter: match, + Command: key.Value(), + Filter: key.Name(), } switch { - case strings.Contains(match, ",~"): + case strings.Contains(filter.Filter, ",~"): filter.Type = FILTER_HEADER //nolint:gocritic // guarded by strings.Contains header := filter.Filter[:strings.Index(filter.Filter, ",")] @@ -46,7 +45,7 @@ func (config *AercConfig) parseFilters(file *ini.File) error { if err != nil { return err } - case strings.ContainsRune(match, ','): + case strings.ContainsRune(filter.Filter, ','): filter.Type = FILTER_HEADER //nolint:gocritic // guarded by strings.Contains header := filter.Filter[:strings.Index(filter.Filter, ",")] |