From c7724f2b22d6918b55197d00d34b49b8e02a5ce5 Mon Sep 17 00:00:00 2001 From: Jake MacDonald Date: Tue, 15 Apr 2025 10:50:14 -0700 Subject: [PATCH 1/2] drop dependencies on matcher and quiver, drop matcher library --- CHANGELOG.md | 8 +++++-- lib/matchers.dart | 45 --------------------------------------- lib/src/uri_pattern.dart | 18 +++++++++++----- lib/src/uri_template.dart | 8 +++---- pubspec.yaml | 4 +--- 5 files changed, 23 insertions(+), 60 deletions(-) delete mode 100644 lib/matchers.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b3b6e1..6858158 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ -## 1.1.0-wip +## 2.0.0 - Require Dart 3.1.0 or greater. -- No longer explicitly name the `matchers.dart` library as `uri.matchers`. +- Drop support for the `matchers` library, so that we can drop the dependency + on `matcher`. + - If you need this, please file a request for a new package to be published + with just the matcher functionality. +- Drop the dependency on `quiver`. ## 1.0.0 diff --git a/lib/matchers.dart b/lib/matchers.dart deleted file mode 100644 index 283cb54..0000000 --- a/lib/matchers.dart +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:matcher/matcher.dart' show Matcher, anything, isA; - -/// Matches the individual parts of a [Uri]. If a matcher is not specified for a -/// part, the default matcher is [anything]. This allows you to just match on a -/// single part, like the scheme, while ignoring the rest. -Matcher matchesUri({ - Object? fragment = anything, - Object? host = anything, - Object? path = anything, - Object? port = anything, - Object? queryParameters = anything, - Object? scheme = anything, - Object? userInfo = anything, -}) => - isA() - .having((e) => e.fragment, 'fragment', fragment) - .having((e) => e.host, 'host', host) - .having((e) => e.path, 'path', path) - .having((e) => e.port, 'port', port); - -/* - _feature('Uri', 'path', path, (i) => i.path), - _feature('Uri', 'port', port, (i) => i.port), - _feature( - 'Uri', 'queryParameters', queryParameters, (i) => i.queryParameters), - _feature('Uri', 'scheme', scheme, (i) => i.scheme), - _feature('Uri', 'userInfo', userInfo, (i) => userInfo) - ]); -*/ - -/// Matches the parts of a [Uri] against [expected], all of which must equal for -/// the match to pass. -Matcher equalsUri(Uri expected) => matchesUri( - fragment: expected.fragment, - host: expected.host, - path: expected.path, - port: expected.port, - queryParameters: expected.queryParameters, - scheme: expected.scheme, - userInfo: expected.userInfo, - ); diff --git a/lib/src/uri_pattern.dart b/lib/src/uri_pattern.dart index b1ff141..33e933b 100644 --- a/lib/src/uri_pattern.dart +++ b/lib/src/uri_pattern.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:quiver/collection.dart' show mapsEqual; -import 'package:quiver/core.dart' show hash4; - /// An interface for objects that match [Uri]s. abstract class UriPattern { /// Returns `true` if [uri] is matched by this pattern. @@ -45,9 +42,20 @@ class UriMatch { other is UriMatch && pattern == other.pattern && input == other.input && - mapsEqual(parameters, other.parameters) && + parameters.equals(other.parameters) && rest == other.rest; @override - int get hashCode => hash4(pattern, input, parameters.toString(), rest); + int get hashCode => Object.hash(pattern, input, parameters.toString(), rest); +} + +extension on Map { + bool equals(Map other) { + if (length != other.length) return false; + for (var entry in entries) { + if (!other.containsKey(entry.key)) return false; + if (other[entry.key] != entry.value) return false; + } + return true; + } } diff --git a/lib/src/uri_template.dart b/lib/src/uri_template.dart index 37fa83e..2c836f7 100644 --- a/lib/src/uri_template.dart +++ b/lib/src/uri_template.dart @@ -4,8 +4,6 @@ import 'dart:collection' show UnmodifiableListView; -import 'package:quiver/pattern.dart' show escapeRegex; - import 'encoding.dart'; import 'uri_builder.dart'; import 'uri_pattern.dart'; @@ -371,7 +369,7 @@ class _Compiler { for (var i = 0; i < subparts.length; i++) { final subpart = subparts[i]; if (subpart is String) { - pathBuffer.write('(?:${escapeRegex(subpart)})'); + pathBuffer.write('(?:${RegExp.escape(subpart)})'); } else if ((subpart as Match).group(1) == '?') { _compileQuery(prevParts: subparts.sublist(i + 1)); break; @@ -482,7 +480,7 @@ class _Compiler { for (var i = 0; i < prevParts.length; i++) { final subpart = prevParts[i]; if (subpart is String) { - fragmentBuffer.write('(?:${escapeRegex(subpart)})'); + fragmentBuffer.write('(?:${RegExp.escape(subpart)})'); } else if ((subpart as Match).group(1) == '?') { throw ParseException('?'); } else if (subpart.group(1) == '#') { @@ -493,7 +491,7 @@ class _Compiler { while (_parts.moveNext()) { final part = _parts.current; if (part is String) { - fragmentBuffer.write('(?:${escapeRegex(part)})'); + fragmentBuffer.write('(?:${RegExp.escape(part)})'); } else { final match = part as Match; final op = match.group(2); diff --git a/pubspec.yaml b/pubspec.yaml index df34b68..06f1198 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: uri -version: 1.1.0-wip +version: 2.0.0 description: >- Utilities for building and parsing URIs, including support for parsing URI templates as defined in RFC 6570. @@ -8,8 +8,6 @@ environment: sdk: ^3.1.0 dependencies: - matcher: ^0.12.10 - quiver: ^3.0.0 dev_dependencies: dart_flutter_team_lints: ^3.0.0 From a984a12e57fb25721098feedea5aa321aa5962dc Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 15 Apr 2025 19:10:46 +0000 Subject: [PATCH 2/2] use -wip version --- CHANGELOG.md | 2 +- pubspec.yaml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6858158..299d05a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.0 +## 2.0.0-wip - Require Dart 3.1.0 or greater. - Drop support for the `matchers` library, so that we can drop the dependency diff --git a/pubspec.yaml b/pubspec.yaml index 06f1198..47e9e01 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: uri -version: 2.0.0 +version: 2.0.0-wip description: >- Utilities for building and parsing URIs, including support for parsing URI templates as defined in RFC 6570. @@ -7,8 +7,6 @@ repository: https://github.com/google/uri.dart environment: sdk: ^3.1.0 -dependencies: - dev_dependencies: dart_flutter_team_lints: ^3.0.0 test: ^1.16.6