[GH-ISSUE #164] Space char not properly escaped in urlEncodedStringWithEncoding extension #98

Closed
opened 2026-03-03 16:45:39 +03:00 by kerem · 1 comment
Owner

Originally created by @dscottbuch on GitHub (Dec 23, 2015).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/164

I didn't find this elsewhere in the tickets. I found that in

    func urlEncodedStringWithEncoding(encoding: NSStringEncoding) -> String {
        let originalString: NSString = self
        let customAllowedSet =  NSCharacterSet(charactersInString:":/?&=;+!@#$()',*=\"#%/<>?@\\^`{|} ").invertedSet
        let escapedString = originalString.stringByAddingPercentEncodingWithAllowedCharacters(customAllowedSet)
        return escapedString! as String
    }

the set of dis-allowed characters in the NSCharacterSet call did not include a space ' '. This would cause the forces unwrapped optional at the end of the URLByAppendingQueryString call to fail every time if the query being attempted contained a space. Added a ' ' to the list of characters fixes this.

Scott

Originally created by @dscottbuch on GitHub (Dec 23, 2015). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/164 I didn't find this elsewhere in the tickets. I found that in ``` swift func urlEncodedStringWithEncoding(encoding: NSStringEncoding) -> String { let originalString: NSString = self let customAllowedSet = NSCharacterSet(charactersInString:":/?&=;+!@#$()',*=\"#%/<>?@\\^`{|} ").invertedSet let escapedString = originalString.stringByAddingPercentEncodingWithAllowedCharacters(customAllowedSet) return escapedString! as String } ``` the set of dis-allowed characters in the NSCharacterSet call did not include a space ' '. This would cause the forces unwrapped optional at the end of the URLByAppendingQueryString call to fail every time if the query being attempted contained a space. Added a ' ' to the list of characters fixes this. Scott
kerem 2026-03-03 16:45:39 +03:00
  • closed this issue
  • added the
    duplicate
    label
Author
Owner

@phimage commented on GitHub (Dec 23, 2015):

it's a duplicate of #156
the dev who open it also close it after creating the PR #157
I reopen it

<!-- gh-comment-id:166968958 --> @phimage commented on GitHub (Dec 23, 2015): it's a duplicate of #156 the dev who open it also close it after creating the PR #157 I reopen it
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#98
No description provided.