| Index: sdk/lib/_internal/js_runtime/lib/core_patch.dart
|
| diff --git a/sdk/lib/_internal/js_runtime/lib/core_patch.dart b/sdk/lib/_internal/js_runtime/lib/core_patch.dart
|
| index 7d6ad7c244533fc8af009361b01a016c19aae16b..a9832709b21b2fe46243d8e73e18eb8874e2c62c 100644
|
| --- a/sdk/lib/_internal/js_runtime/lib/core_patch.dart
|
| +++ b/sdk/lib/_internal/js_runtime/lib/core_patch.dart
|
| @@ -527,6 +527,47 @@ class Uri {
|
| if (uri != null) return Uri.parse(uri);
|
| throw new UnsupportedError("'Uri.base' is not supported");
|
| }
|
| +
|
| +
|
| + // 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.
|
| + */
|
| + @patch
|
| + static String _uriEncode(List<int> canonicalTable,
|
| + String text,
|
| + Encoding encoding,
|
| + bool spaceToPlus) {
|
| + if (identical(encoding, UTF8) && _needsNoEncoding.hasMatch(text)) {
|
| + return text;
|
| + }
|
| +
|
| + // 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 {
|
| + const String hexDigits = '0123456789ABCDEF';
|
| + result.writeCharCode(_PERCENT);
|
| + result.writeCharCode(hexDigits.codeUnitAt(byte >> 4));
|
| + result.writeCharCode(hexDigits.codeUnitAt(byte & 0x0f));
|
| + }
|
| + }
|
| + return result.toString();
|
| + }
|
| }
|
|
|
| @patch
|
|
|