Custom URI scheme removes spaces before the “hashtag sign” (#)

旧时模样 提交于 2019-12-12 02:48:58

问题


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 launch alert.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!