diff --git a/packages/flutter_web_plugins/lib/src/navigation/utils.dart b/packages/flutter_web_plugins/lib/src/navigation/utils.dart
index 5cb18924db2..5624c4bde86 100644
--- a/packages/flutter_web_plugins/lib/src/navigation/utils.dart
+++ b/packages/flutter_web_plugins/lib/src/navigation/utils.dart
@@ -2,28 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'dart:html';
-
-final AnchorElement _urlParsingNode = AnchorElement();
-
/// Extracts the pathname part of a full [url].
///
/// Example: for the url `http://example.com/foo`, the extracted pathname will
/// be `/foo`.
String extractPathname(String url) {
- _urlParsingNode.href = url; // ignore: unsafe_html, node is never exposed to the user
- final String pathname = _urlParsingNode.pathname ?? '';
- return (pathname.isEmpty || pathname[0] == '/') ? pathname : '/$pathname';
+ return ensureLeadingSlash(Uri.parse(url).path);
}
-// The element in the document.
-final Element? _baseElement = document.querySelector('base');
-
-/// Returns the `href` attribute of the element in the document.
-///
-/// Returns null if the element isn't found.
-String? getBaseElementHrefFromDom() => _baseElement?.getAttribute('href');
-
/// Checks that [baseHref] is set.
///
/// Throws an exception otherwise.
diff --git a/packages/flutter_web_plugins/pubspec.yaml b/packages/flutter_web_plugins/pubspec.yaml
index 494097bdc40..16368f2b091 100644
--- a/packages/flutter_web_plugins/pubspec.yaml
+++ b/packages/flutter_web_plugins/pubspec.yaml
@@ -9,10 +9,9 @@ dependencies:
flutter:
sdk: flutter
- js: 0.6.7
-
characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
collection: 1.17.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
+ js: 0.6.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
material_color_utilities: 0.5.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
meta: 1.9.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
diff --git a/packages/flutter_web_plugins/test/navigation/utils_test.dart b/packages/flutter_web_plugins/test/navigation/utils_test.dart
index b3690586135..0bfc64594ec 100644
--- a/packages/flutter_web_plugins/test/navigation/utils_test.dart
+++ b/packages/flutter_web_plugins/test/navigation/utils_test.dart
@@ -33,5 +33,9 @@ void main() {
expect(extractPathname('https://example.com/foo'), '/foo');
expect(extractPathname('https://example.com/foo#bar'), '/foo');
expect(extractPathname('https://example.com/foo/#bar'), '/foo/');
+
+ // URL encoding.
+ expect(extractPathname('/foo bar'), '/foo%20bar');
+ expect(extractPathname('https://example.com/foo bar'), '/foo%20bar');
});
}