Is this a valid URL, and if so, why doesn't NSURL recognize its request?

myscheme:?id=test

If I pass this on [NSURL URLWithString:]and print its property query, I get it nil, but if I put a slash right after the colon (or two or three), it works fine.

Is this really an invalid url or is it an error in NSURL?

According to some studies, it appears to be a valid URL. From http://url.spec.whatwg.org/ :

The absolute URL should be a scheme, followed by a ":", and then a data scheme, optionally followed by a "?" and request.

and (highlighted by me)

The syntax of the schema data is dependent on the schema and usually with it. For a relative scheme, the scheme data must be the URL of the scheme. For other circuits , specifications, or standards, it must define these circuits within the limits of zero or more . units

+1
source share
2 answers

myscheme:?id=test- a valid URL, but NSURLrecognizes it as such, returning not nilfrom +URLWithString:.

However, in RFC 1808, it does not match in such a way that it NSURLrecognizes the character ?as indicating a query string, therefore -queryreturns nil.

, NSURLComponents , ? :

NSURLComponents *components = [NSURLComponents componentsWithString:@"myscheme:?id=test"];
return components.query; // returns @"id=test"

iOS 6 , KSURLComponents, .

+2

( URL?), NSURL ( , , NSURL URL-).

myscheme:?id=test URL, myscheme URI. URI http://www.iana.org/assignments/uri-schemes.html.

URI , URI:

URI    , , , ,     , 4.3.

:

absolute-URI  = scheme ":" hier-part [ "?" query ]

hier-part ( STD 66). , URI, URI ( URI , , , ).

+1

Source: https://habr.com/ru/post/1665121/


All Articles