File tree Expand file tree Collapse file tree 3 files changed +6
-17
lines changed
packages/flutter_web_plugins Expand file tree Collapse file tree 3 files changed +6
-17
lines changed Original file line number Diff line number Diff line change 22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- import 'dart:html' ;
6-
7- final AnchorElement _urlParsingNode = AnchorElement ();
8-
95/// Extracts the pathname part of a full [url] .
106///
117/// Example: for the url `http://example.com/foo` , the extracted pathname will
128/// be `/foo` .
139String extractPathname (String url) {
14- _urlParsingNode.href = url; // ignore: unsafe_html, node is never exposed to the user
15- final String pathname = _urlParsingNode.pathname ?? '' ;
16- return (pathname.isEmpty || pathname[0 ] == '/' ) ? pathname : '/$pathname ' ;
10+ return ensureLeadingSlash (Uri .parse (url).path);
1711}
1812
19- // The <base> element in the document.
20- final Element ? _baseElement = document.querySelector ('base' );
21-
22- /// Returns the `href` attribute of the <base> element in the document.
23- ///
24- /// Returns null if the element isn't found.
25- String ? getBaseElementHrefFromDom () => _baseElement? .getAttribute ('href' );
26-
2713/// Checks that [baseHref] is set.
2814///
2915/// Throws an exception otherwise.
Original file line number Diff line number Diff line change @@ -9,10 +9,9 @@ dependencies:
99 flutter :
1010 sdk : flutter
1111
12- js : 0.6.7
13-
1412 characters : 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
1513 collection : 1.17.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
14+ js : 0.6.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
1615 material_color_utilities : 0.5.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
1716 meta : 1.9.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
1817 vector_math : 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
Original file line number Diff line number Diff line change @@ -33,5 +33,9 @@ void main() {
3333 expect (extractPathname ('https://example.com/foo' ), '/foo' );
3434 expect (extractPathname ('https://example.com/foo#bar' ), '/foo' );
3535 expect (extractPathname ('https://example.com/foo/#bar' ), '/foo/' );
36+
37+ // URL encoding.
38+ expect (extractPathname ('/foo bar' ), '/foo%20bar' );
39+ expect (extractPathname ('https://example.com/foo bar' ), '/foo%20bar' );
3640 });
3741}
You can’t perform that action at this time.
0 commit comments