~rjarry/aerc

eebb85a9d5bd35b460d5cf89a0cadcfce5b68137 — Robin Jarry 17 days ago 4db1353
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>
1 files changed, 5 insertions(+), 6 deletions(-)

M config/filters.go
M config/filters.go => config/filters.go +5 -6
@@ 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, ",")]