Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Unified Diff: sdk/lib/core/uri.dart

Issue 1416373007: Split _uriEncode into JS and VM versions. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/core/uri.dart
diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart
index 3abd352c1ae8e120a6934fe312c064132de29af1..1a8aa7a715ae32ac541c57ea2d905ec96d7ffdf0 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -1242,7 +1242,8 @@ class Uri {
if (path != null) {
result = _normalize(path, start, end, _pathCharOrSlashTable);
} else {
- result = pathSegments.map((s) => _uriEncode(_pathCharTable, s)).join("/");
+ result = pathSegments.map((s) =>
+ _uriEncode(_pathCharTable, s, UTF8, false)).join("/");
}
if (result.isEmpty) {
if (isFile) return "/";
@@ -1952,7 +1953,7 @@ class Uri {
* a [Uri].
*/
static String encodeComponent(String component) {
- return _uriEncode(_unreserved2396Table, component);
+ return _uriEncode(_unreserved2396Table, component, UTF8, false);
}
/**
@@ -1990,8 +1991,7 @@ class Uri {
*/
static String encodeQueryComponent(String component,
{Encoding encoding: UTF8}) {
- return _uriEncode(
- _unreservedTable, component, encoding: encoding, spaceToPlus: true);
+ return _uriEncode(_unreservedTable, component, encoding, true);
}
/**
@@ -2035,7 +2035,7 @@ class Uri {
* the encodeURI function .
*/
static String encodeFull(String uri) {
- return _uriEncode(_encodeFullTable, uri);
+ return _uriEncode(_encodeFullTable, uri, UTF8, false);
}
/**
@@ -2251,46 +2251,10 @@ class Uri {
static const int _LOWER_CASE_Z = 0x7A;
static const int _BAR = 0x7C;
- // Matches a String that _uriEncodes to itself regardless of the kind of
- // component. This corresponds to [_unreservedTable], i.e. characters that
- // are not encoded by any encoding table.
- static final RegExp _needsNoEncoding = new RegExp(r'^[\-\.0-9A-Z_a-z~]*$');
-
- /**
- * This is the internal implementation of JavaScript's encodeURI function.
- * It encodes all characters in the string [text] except for those
- * that appear in [canonicalTable], and returns the escaped string.
- */
- static String _uriEncode(List<int> canonicalTable,
- String text,
- {Encoding encoding: UTF8,
- bool spaceToPlus: false}) {
- if (_needsNoEncoding.hasMatch(text)) return text;
-
- byteToHex(byte, buffer) {
- const String hex = '0123456789ABCDEF';
- buffer.writeCharCode(hex.codeUnitAt(byte >> 4));
- buffer.writeCharCode(hex.codeUnitAt(byte & 0x0f));
- }
-
- // Encode the string into bytes then generate an ASCII only string
- // by percent encoding selected bytes.
- StringBuffer result = new StringBuffer();
- var bytes = encoding.encode(text);
- for (int i = 0; i < bytes.length; i++) {
- int byte = bytes[i];
- if (byte < 128 &&
- ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) {
- result.writeCharCode(byte);
- } else if (spaceToPlus && byte == _SPACE) {
- result.writeCharCode(_PLUS);
- } else {
- result.writeCharCode(_PERCENT);
- byteToHex(byte, result);
- }
- }
- return result.toString();
- }
+ external static String _uriEncode(List<int> canonicalTable,
+ String text,
+ Encoding encoding,
+ bool spaceToPlus);
Lasse Reichstein Nielsen 2015/11/04 10:15:53 I made the parameters non-optional. That's what I
/**
* Convert a byte (2 character hex sequence) in string [s] starting

Powered by Google App Engine
This is Rietveld 408576698