Skip to content

Instantly share code, notes, and snippets.

@below
Created July 26, 2016 21:18
Show Gist options
  • Select an option

  • Save below/15bb184ea100326bdb96cdacf6af67f6 to your computer and use it in GitHub Desktop.

Select an option

Save below/15bb184ea100326bdb96cdacf6af67f6 to your computer and use it in GitHub Desktop.
Why is NSQueryItem not percent escaping "+" in a query?
import UIKit
let comps = NSURLComponents(string: "https://example.com")
comps?.queryItems = [NSURLQueryItem(name: "foobar", value: "foo+bar&something else")]
comps!.URL!
// Actual result:
// https://example.com?foobar=foo+bar%26something%20else
// As per https://tools.ietf.org/html/rfc3986#section-2.1 it
// appears that '+' should be escaped. What am I overlooking?
@below

below commented Jul 26, 2016

Copy link
Copy Markdown
Author

While "+" is legal, some systems mess it up. So therefore, here is the solution: http://stackoverflow.com/questions/31577188/how-to-encode-into-2b-with-nsurlcomponents/37314144#37314144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment