Reapply "Fix URI encoding/decoding of + and space""

Updated test expectations for some tests for pkg/http, pkg/oauth2 and
pub to match the change.

TBR=lrn@google.com

Review URL: https://codereview.chromium.org//11659009

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16426 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
sgjesse@google.com 2012-12-21 09:50:05 +00:00
parent f020a7d270
commit 7e293aa077
7 changed files with 24 additions and 14 deletions

View file

@ -56,11 +56,11 @@ main() {
'content-type': [
'application/x-www-form-urlencoded; charset=UTF-8'
],
'content-length': ['42'],
'content-length': ['40'],
'x-random-header': ['Value'],
'x-other-header': ['Other Value']
},
'body': 'some-field=value&other-field=other%20value'
'body': 'some-field=value&other-field=other+value'
})));
}), completes);
});
@ -101,11 +101,11 @@ main() {
'content-type': [
'application/x-www-form-urlencoded; charset=UTF-8'
],
'content-length': ['42'],
'content-length': ['40'],
'x-random-header': ['Value'],
'x-other-header': ['Other Value']
},
'body': 'some-field=value&other-field=other%20value'
'body': 'some-field=value&other-field=other+value'
})));
}), completes);
});

View file

@ -50,7 +50,7 @@ void main() {
'?response_type=code'
'&client_id=identifier'
'&redirect_uri=http%3A%2F%2Fexample.com%2Fredirect'
'&scope=scope%20other%2Fscope'));
'&scope=scope+other%2Fscope'));
});
test('builds the correct URL with state', () {

View file

@ -22,7 +22,7 @@ part of dart.uri;
*/
String encodeUri(String uri) {
return _uriEncode(
"-_.!~*'()#;,/?:@&=+\$0123456789"
"-_.!~*'()#;,/?:@&=\$0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", uri);
}
@ -82,6 +82,8 @@ String _uriEncode(String canonical, String text) {
for (int i = 0; i < text.length; i++) {
if (canonical.indexOf(text[i]) >= 0) {
result.add(text[i]);
} else if (text[i] == " ") {
result.add("+");
} else {
int ch = text.charCodeAt(i);
if (ch >= 0xD800 && ch < 0xDC00) {
@ -137,7 +139,11 @@ String _uriDecode(String text) {
for (int i = 0; i < text.length;) {
String ch = text[i];
if (ch != '%') {
result.add(ch);
if (ch == '+') {
result.add(" ");
} else {
result.add(ch);
}
i++;
} else {
codepoints.clear();

View file

@ -17,6 +17,9 @@ void testParseEncodedString() {
String encodedString = 'foo+bar%20foobar%25%26';
Expect.equals(_HttpUtils.decodeUrlEncodedString(encodedString),
'foo bar foobar%&');
encodedString = 'A+%2B+B';
Expect.equals(_HttpUtils.decodeUrlEncodedString(encodedString),
'A + B');
}
void testParseQueryString() {

View file

@ -192,6 +192,7 @@ main() {
Expect.stringEquals("\u{10000}", s);
testEncodeDecode("A + B", "A+%2B+B");
testEncodeDecode("\uFFFE", "%EF%BF%BE");
testEncodeDecode("\uFFFF", "%EF%BF%BF");
testEncodeDecode("\uFFFE", "%EF%BF%BE");
@ -199,7 +200,7 @@ main() {
testEncodeDecode("\x7f", "%7F");
testEncodeDecode("\x80", "%C2%80");
testEncodeDecode("\u0800", "%E0%A0%80");
testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$");
testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=%2B\$");
testEncodeDecode(s, "%F0%90%80%80");
testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE");
testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF");

View file

@ -58,11 +58,11 @@ void main() {
'content-type': [
'application/x-www-form-urlencoded; charset=UTF-8'
],
'content-length': ['42'],
'content-length': ['40'],
'x-random-header': ['Value'],
'x-other-header': ['Other Value']
},
'body': 'some-field=value&other-field=other%20value'
'body': 'some-field=value&other-field=other+value'
})));
}), completes);
});
@ -102,11 +102,11 @@ void main() {
'content-type': [
'application/x-www-form-urlencoded; charset=UTF-8'
],
'content-length': ['42'],
'content-length': ['40'],
'x-random-header': ['Value'],
'x-other-header': ['Other Value']
},
'body': 'some-field=value&other-field=other%20value'
'body': 'some-field=value&other-field=other+value'
})));
}), completes);
});

View file

@ -71,7 +71,7 @@ main() {
return consumeInputStream(request.inputStream).transform((bytes) {
var body = new String.fromCharCodes(bytes);
expect(body, matches(
new RegExp(r'(^|&)refresh_token=refresh%20token(&|$)')));
new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)')));
response.headers.contentType = new ContentType("application", "json");
response.outputStream.writeString(JSON.stringify({
@ -211,7 +211,7 @@ void handleAccessTokenRequest(ScheduledServer server, String accessToken) {
server.handle('POST', '/token', (request, response) {
return consumeInputStream(request.inputStream).transform((bytes) {
var body = new String.fromCharCodes(bytes);
expect(body, matches(new RegExp(r'(^|&)code=access%20code(&|$)')));
expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)')));
response.headers.contentType = new ContentType("application", "json");
response.outputStream.writeString(JSON.stringify({