From a553089e519e1bc9def373296edcd98a8984e0a3 Mon Sep 17 00:00:00 2001 From: suojae Date: Mon, 27 Jan 2025 04:00:16 +0900 Subject: [PATCH 1/6] Fix: Ensure ListParam equality uses DeepCollectionEquality for caching --- dio/CHANGELOG.md | 1 + dio/lib/src/parameter.dart | 6 ++++-- dio/pubspec.yaml | 1 + dio/test/parameter_test.dart | 13 +++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 dio/test/parameter_test.dart diff --git a/dio/CHANGELOG.md b/dio/CHANGELOG.md index 491ea0680..be13c35aa 100644 --- a/dio/CHANGELOG.md +++ b/dio/CHANGELOG.md @@ -9,6 +9,7 @@ See the [Migration Guide][] for the complete breaking changes list.** - Removes redundant warnings when composing request options on Web. - Fixes boundary inconsistency in `FormData.clone()`. - Support `FileAccessMode` in `Dio.download` and `Dio.downloadUri` to change download file opening mode +- Fix Ensure `ListParam` equality uses `DeepCollectionEquality` for proper caching and comparison. ## 5.7.0 diff --git a/dio/lib/src/parameter.dart b/dio/lib/src/parameter.dart index ef44df948..8711e8ce5 100644 --- a/dio/lib/src/parameter.dart +++ b/dio/lib/src/parameter.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'options.dart'; /// Indicates a param being used as queries or form data, @@ -26,9 +27,10 @@ class ListParam { identical(this, other) || other is ListParam && runtimeType == other.runtimeType && - value == other.value && + const DeepCollectionEquality().equals(value, other.value) && format == other.format; @override - int get hashCode => value.hashCode ^ format.hashCode; + int get hashCode => + const DeepCollectionEquality().hash(value) ^ format.hashCode; } diff --git a/dio/pubspec.yaml b/dio/pubspec.yaml index dc2a19070..ab5908ec3 100644 --- a/dio/pubspec.yaml +++ b/dio/pubspec.yaml @@ -26,6 +26,7 @@ dependencies: path: ^1.8.0 dio_web_adapter: '>=1.0.0 <3.0.0' + collection: ^1.19.1 dev_dependencies: lints: any diff --git a/dio/test/parameter_test.dart b/dio/test/parameter_test.dart new file mode 100644 index 000000000..9ba1cd6b9 --- /dev/null +++ b/dio/test/parameter_test.dart @@ -0,0 +1,13 @@ +import 'package:dio/dio.dart'; +import 'package:test/test.dart'; + +void main() { + test('ListParam equality for Map key', () { + final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); + final param2 = const ListParam(['item1', 'item2'], ListFormat.csv); + + final cache = {param1: 'Cached Response'}; + + expect(cache.containsKey(param2), true, reason: 'param1 and param2 should be considered equal'); + }); +} From 3e44fcb64bd742d217c7ae80451a56a5c3da8e4d Mon Sep 17 00:00:00 2001 From: suojae Date: Mon, 27 Jan 2025 12:32:13 +0900 Subject: [PATCH 2/6] chore: downgrade collection version and apply dart format --- dio/pubspec.yaml | 4 ++-- dio/test/parameter_test.dart | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dio/pubspec.yaml b/dio/pubspec.yaml index ab5908ec3..6a609250f 100644 --- a/dio/pubspec.yaml +++ b/dio/pubspec.yaml @@ -24,9 +24,9 @@ dependencies: http_parser: ^4.0.0 meta: ^1.5.0 path: ^1.8.0 - + collection: '>=1.16.0 <2.0.0' + dio_web_adapter: '>=1.0.0 <3.0.0' - collection: ^1.19.1 dev_dependencies: lints: any diff --git a/dio/test/parameter_test.dart b/dio/test/parameter_test.dart index 9ba1cd6b9..56a73743a 100644 --- a/dio/test/parameter_test.dart +++ b/dio/test/parameter_test.dart @@ -8,6 +8,10 @@ void main() { final cache = {param1: 'Cached Response'}; - expect(cache.containsKey(param2), true, reason: 'param1 and param2 should be considered equal'); + expect( + cache.containsKey(param2), + true, + reason: 'param1 and param2 should be considered equal', + ); }); } From a1ad23f4c6eacb8ad737e60c50737d144d0a2ff1 Mon Sep 17 00:00:00 2001 From: suojae Date: Mon, 27 Jan 2025 22:48:18 +0900 Subject: [PATCH 3/6] chore: adjust collection dependency and import formatting --- dio/lib/src/parameter.dart | 1 + dio/pubspec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dio/lib/src/parameter.dart b/dio/lib/src/parameter.dart index 8711e8ce5..28959eab3 100644 --- a/dio/lib/src/parameter.dart +++ b/dio/lib/src/parameter.dart @@ -1,4 +1,5 @@ import 'package:collection/collection.dart'; + import 'options.dart'; /// Indicates a param being used as queries or form data, diff --git a/dio/pubspec.yaml b/dio/pubspec.yaml index 6a609250f..ab95036f7 100644 --- a/dio/pubspec.yaml +++ b/dio/pubspec.yaml @@ -21,11 +21,11 @@ environment: dependencies: async: ^2.8.2 + collection: '^1.16.0' http_parser: ^4.0.0 meta: ^1.5.0 path: ^1.8.0 - collection: '>=1.16.0 <2.0.0' - + dio_web_adapter: '>=1.0.0 <3.0.0' dev_dependencies: From 820b0bfcd3dca5f920ae3b754b17bc07ee6a8d3d Mon Sep 17 00:00:00 2001 From: suojae Date: Mon, 27 Jan 2025 23:03:22 +0900 Subject: [PATCH 4/6] test: add test cases for ListParam equality - Added test cases to validate unequal inputs (different values, different order). - Confirmed current behavior considers order in equality checks. --- dio/test/parameter_test.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dio/test/parameter_test.dart b/dio/test/parameter_test.dart index 56a73743a..0c988a830 100644 --- a/dio/test/parameter_test.dart +++ b/dio/test/parameter_test.dart @@ -5,6 +5,8 @@ void main() { test('ListParam equality for Map key', () { final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); final param2 = const ListParam(['item1', 'item2'], ListFormat.csv); + final param3 = const ListParam(['item3', 'item4'], ListFormat.csv); + final param4 = const ListParam(['item2', 'item1'], ListFormat.csv); final cache = {param1: 'Cached Response'}; @@ -13,5 +15,18 @@ void main() { true, reason: 'param1 and param2 should be considered equal', ); + + expect( + cache.containsKey(param3), + false, + reason: 'param1 and param3 should not be considered equal', + ); + + expect( + cache.containsKey(param4), + false, + reason: + 'param1 and param4 should not be considered equal as order matters', + ); }); } From f01072d01f77cbe55ef601c110e7a5204d80ed4c Mon Sep 17 00:00:00 2001 From: suojae Date: Mon, 27 Jan 2025 23:46:39 +0900 Subject: [PATCH 5/6] refactor: replace hashcode implmentation with `Object.hash` --- dio/CHANGELOG.md | 2 +- dio/lib/src/parameter.dart | 6 ++++-- dio/pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dio/CHANGELOG.md b/dio/CHANGELOG.md index be13c35aa..9a1ec45f2 100644 --- a/dio/CHANGELOG.md +++ b/dio/CHANGELOG.md @@ -9,7 +9,7 @@ See the [Migration Guide][] for the complete breaking changes list.** - Removes redundant warnings when composing request options on Web. - Fixes boundary inconsistency in `FormData.clone()`. - Support `FileAccessMode` in `Dio.download` and `Dio.downloadUri` to change download file opening mode -- Fix Ensure `ListParam` equality uses `DeepCollectionEquality` for proper caching and comparison. +- Fix `ListParam` equality by using the `DeepCollectionEquality`. ## 5.7.0 diff --git a/dio/lib/src/parameter.dart b/dio/lib/src/parameter.dart index 28959eab3..38ef47565 100644 --- a/dio/lib/src/parameter.dart +++ b/dio/lib/src/parameter.dart @@ -32,6 +32,8 @@ class ListParam { format == other.format; @override - int get hashCode => - const DeepCollectionEquality().hash(value) ^ format.hashCode; + int get hashCode => Object.hash( + const DeepCollectionEquality().hash(value), + format, + ); } diff --git a/dio/pubspec.yaml b/dio/pubspec.yaml index ab95036f7..3126f410c 100644 --- a/dio/pubspec.yaml +++ b/dio/pubspec.yaml @@ -21,7 +21,7 @@ environment: dependencies: async: ^2.8.2 - collection: '^1.16.0' + collection: ^1.16.0 http_parser: ^4.0.0 meta: ^1.5.0 path: ^1.8.0 From 82e2f03eca0c5efb729f2b04cd46164c96fe64cf Mon Sep 17 00:00:00 2001 From: suojae Date: Tue, 28 Jan 2025 01:21:47 +0900 Subject: [PATCH 6/6] test: refactor ListParam tests to use direct equality comparison and make group --- dio/test/parameter_test.dart | 40 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/dio/test/parameter_test.dart b/dio/test/parameter_test.dart index 0c988a830..f5b32e25f 100644 --- a/dio/test/parameter_test.dart +++ b/dio/test/parameter_test.dart @@ -2,31 +2,23 @@ import 'package:dio/dio.dart'; import 'package:test/test.dart'; void main() { - test('ListParam equality for Map key', () { - final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); - final param2 = const ListParam(['item1', 'item2'], ListFormat.csv); - final param3 = const ListParam(['item3', 'item4'], ListFormat.csv); - final param4 = const ListParam(['item2', 'item1'], ListFormat.csv); + group('ListParam', () { + test('param1 and param2 should be considered equal', () { + final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); + final param2 = const ListParam(['item1', 'item2'], ListFormat.csv); + expect(param1 == param2, isTrue); + }); - final cache = {param1: 'Cached Response'}; + test('param1 and param3 should not be considered equal', () { + final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); + final param3 = const ListParam(['item3', 'item4'], ListFormat.csv); + expect(param1 == param3, isFalse); + }); - expect( - cache.containsKey(param2), - true, - reason: 'param1 and param2 should be considered equal', - ); - - expect( - cache.containsKey(param3), - false, - reason: 'param1 and param3 should not be considered equal', - ); - - expect( - cache.containsKey(param4), - false, - reason: - 'param1 and param4 should not be considered equal as order matters', - ); + test('Order matters: param1 and param4 should not be equal', () { + final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); + final param4 = const ListParam(['item2', 'item1'], ListFormat.csv); + expect(param1 == param4, isFalse); + }); }); }