问题
i'm writing custom URI scheme, following this article:
https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
my handler looks like this: myScheme://firstItem/SecondItem
the thing is, after the first slash, if i write the "#" with spaces, all spaces are removed.
example:
myScheme://first/second #third
is interpreted as:
myScheme://first/second#third
in my application.
in addition, if it's the first parameter before the slash, a slash is added:
myScheme://first #second
is interpreted as:
myScheme://first /#second
in my application.
Can anyone can explain this behavior?
== EDIT ==
mailto: protocol is the only one who is implemented in similar way, and is working well. onenote, winamp, etc... can't handle those cases.
anyone knows why?
回答1:
Usually you use percent-encoded spaces, e.g,.
- In a URL, should spaces be encoded using %20 or +?
- URL encoding the space character: + or %20?
The page Registering an Application to a URI Scheme lists more than one problem with spaces in a URI:
By adding the above settings to the registry, navigating to URIs such as
alert:Hello%20World
would cause an attempt to launchalert.exe
with the complete URI on the command line. Internet Explorer percent-decodes the URI, but the Windows Run... command does not. If a URI contains percent-encoded spaces, it may be split across more than one argument on the command line.
The "split" corresponds to your second part of the question. But later, it comments
When ShellExecute executes the pluggable protocol handler with a stringon the command line, any non-encoded spaces, quotes, and backslashes in the URI will be interpreted as part of the command line. This means that if you use C/C++'s argc and argv to determine the arguments passed to your application, the string may be broken across multiple parameters. To mitigate this issue:
The last part is the recommendation:
Avoid spaces, quotes, or backslashes in your URI
because one part of the system will rely upon percent-encoding while the other is broken by it.
来源:https://stackoverflow.com/questions/33545536/custom-uri-scheme-removes-spaces-before-the-hashtag-sign