Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

CFURLCreateStringByAddingPercentEscapesの変更 (issue #95) #126

Merged
merged 6 commits into from Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions NCMB/NCMBRequest/NCMBRequest.m
Expand Up @@ -78,13 +78,7 @@ +(NSString *)returnSessionToken {
}

+(NSString *)returnEncodedString:(NSString *)originalString {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このメソッドのテストをNCMBTests/NCMBRequestSpec.mに追加してください。

CFStringRef escapedStrRef = CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef)originalString,
NULL,
CFSTR(":/?#[]@!$&'()*+,;="),
kCFStringEncodingUTF8 );
NSString *escapedStr = CFBridgingRelease(escapedStrRef);
NSString *escapedStr = [originalString stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@":/?#[]@!$&'()*+,;=\"<>\\%^`{|} \b\t\n\a\r"] invertedSet]];
return escapedStr;
}

Expand Down
15 changes: 2 additions & 13 deletions NCMB/NCMBURLConnection/NCMBURLConnection.m
Expand Up @@ -107,17 +107,6 @@ - (id)initWithPath:(NSString*)path method:(NSString*)method data:(NSData*)data c
return self;
}

- (NSString*)percentEscape:(NSString*)str{
CFStringRef escapedStrRef = CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef)str,
NULL,
(__bridge CFStringRef)@"!*();@+,%#\"",
kCFStringEncodingUTF8 );
NSString *escapedStr = CFBridgingRelease(escapedStrRef);
return escapedStr;
}


#pragma mark request

Expand All @@ -141,9 +130,9 @@ - (NSString*)returnEndPoint{
@return NSMutableURLRequest型リクエスト
*/
- (NSMutableURLRequest *)createRequest {
self.query = [self percentEscape:self.query];
self.query = [self.query stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"#[]@!()*+,;\"<>\\%^`{|} \b\t\n\a\r"] invertedSet]];
[self createSignature];
self.path = [self percentEscape:self.path];
self.path = [self.path stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"#[]@!()*+,;\"<>\\%^`{|} \b\t\n\a\r"] invertedSet]];

//url生成
NSString *endPointStr = [self returnEndPoint];
Expand Down
13 changes: 13 additions & 0 deletions NCMBTests/NCMBTests/NCMBRequestSpec.m
Expand Up @@ -20,6 +20,7 @@
#import <NCMB/NCMB.h>
#import "NCMBRequest.h"

#import "NCMBURLConnection.h"

SpecBegin(NCMBRequest)

Expand All @@ -37,6 +38,18 @@

});

it(@"should create connection with query string and path have special symbols inside", ^{

NCMBURLConnection *connection = [[NCMBURLConnection alloc] init];
[connection setQuery:@"/2013-09-01/classes?limit=1&where={\"name\":null}"];
[connection setPath:@"classes/<MyCl@ass>"];
[connection syncConnection:nil];

expect(connection.query).to.equal(@"/2013-09-01/classes?limit=1&where=%7B%22name%22:null%7D");
expect(connection.path).to.equal(@"classes/%3CMyCl%40ass%3E");

});

it(@"should set required HTTP request Headers", ^{

NSString *urlStr = @"https://mb.api.cloud.nifty.com/2013-09-01/classes/TestClass?where=%7B%22testKey%22%3A%22testValue%22%7D";
Expand Down
23 changes: 23 additions & 0 deletions NCMBTests/NCMBTests/NCMBScriptServiceSpec.m
Expand Up @@ -98,6 +98,29 @@
expect(service.request.URL.absoluteString).to.equal(expectStr);
});

it (@"should create request with specified query string with special symbols", ^{
NCMBScriptService *service = [[NCMBScriptService alloc] init];

[service executeScript:@"testScript.js"
method:NCMBExecuteWithGetMethod
header:nil
body:nil
query:@{@"number":@12345,
@"string":@"start:/?#[]@!$&'()*+,;=\"<>\\%^`{|} \n\r%@€™ŽĶ¶¹end",
@"array":@[@"value#1>",@"?value#2["],
@"dictionary":@{@"key":@"value"},
@"bool":@YES}
withBlock:nil];

NSString *expectStr = [NSString stringWithFormat:@"%@/%@/%@/%@?%@",
NCMBScriptServiceDefaultEndPoint,
NCMBScriptServiceApiVersion,
NCMBScriptServicePath,
@"testScript.js",
@"array=%5B%22value%231%3E%22%2C%22%3Fvalue%232%5B%22%5D&bool=1&dictionary=%7B%22key%22%3A%22value%22%7D&number=12345&string=start%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%22%3C%3E%5C%25%5E%60%7B%7C%7D%20%20%20%0A%0D%25%40%E2%82%AC%E2%84%A2%C5%BD%C4%B6%C2%B6%C2%B9end"];
expect(service.request.URL.absoluteString).to.equal(expectStr);
});

it(@"should run callback response of execute asynchronously script", ^{
waitUntil(^(DoneCallback done) {

Expand Down