diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a45adc63..c7ca9e06e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ## Unreleased: mitmproxy next +- Fix `view.settings.setval.toggle` command to correctly use the provided key parameter instead of hardcoded "key" string. + ([#8167](https://github.com/mitmproxy/mitmproxy/pull/8167), @nameearly) - Fix 400 Bad Request for HTTP requests with uppercase scheme (e.g. `HTTP://`). ([#8174](https://github.com/mitmproxy/mitmproxy/pull/8174), @emanuele-em) - Fix console command panel losing focus due to incoming traffic (e.g. websocket messages). diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index 5561be572..b9c323d9b 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -394,7 +394,7 @@ class View(collections.abc.Sequence): """ updated = [] for f in flows: - current = self.settings[f].get("key", "false") + current = self.settings[f].get(key, "false") self.settings[f][key] = "false" if current == "true" else "true" updated.append(f) ctx.master.addons.trigger(hooks.UpdateHook(updated)) diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index 5ee0873c8..6d75beedd 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -393,6 +393,13 @@ def test_setgetval(): v.setvalue_toggle([f], "key") assert v.getvalue(f, "key", "default") == "false" + # Test with a different key name to verify the fix for hardcoded "key" bug + v.setvalue([f], "custom_setting", "true") + v.setvalue_toggle([f], "custom_setting") + assert v.getvalue(f, "custom_setting", "default") == "false" + v.setvalue_toggle([f], "custom_setting") + assert v.getvalue(f, "custom_setting", "default") == "true" + def test_order(): v = view.View()