自定义URI方案删除了​​“井号"前的空格. (#) [英] Custom URI scheme removes spaces before the "hashtag sign" (#)

查看:109
本文介绍了自定义URI方案删除了​​“井号"前的空格. (#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本文之后,我正在编写自定义URI方案:

i'm writing custom URI scheme, following this article:

https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx

我的处理程序如下所示: myScheme://firstItem/SecondItem

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.

示例:

myScheme://first/second #third

被解释为:

myScheme://first/second#third

在我的应用程序中.

此外,如果它是斜杠前的第一个参数,则会添加一个斜杠:

in addition, if it's the first parameter before the slash, a slash is added:

myScheme://first #second

被解释为:

myScheme://first /#second

在我的应用程序中.

任何人都可以解释这种行为吗?

Can anyone can explain this behavior?

==编辑==

mailto:协议是唯一以类似方式实现的协议,并且运行良好. onenote,winamp等……无法处理这些情况.

mailto: protocol is the only one who is implemented in similar way, and is working well. onenote, winamp, etc... can't handle those cases.

有人知道为什么吗?

推荐答案

通常,您使用百分比编码的空格,例如.

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?

页面 注册应用于URI方案 列出了URI中多个空格的问题:

The page Registering an Application to a URI Scheme lists more than one problem with spaces in a URI:

通过将以上设置添加到注册表中,导航到诸如alert:Hello%20World的URI将导致尝试在命令行上使用完整的URI启动alert.exe. Internet Explorer百分号解码了URI,但Windows Run ...命令没有.如果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

当ShellExecute在命令行上使用字符串执行可插拔协议处理程序时,URI中任何未编码的空格,引号和反斜杠将被解释为命令行的一部分.这意味着,如果您使用C/C ++的argc和argv来确定传递给应用程序的参数,则该字符串可能会在多个参数中被打乱.为缓解此问题:

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:

最后一部分是建议:

URI中的

避免 空格,引号或反斜杠

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.

这篇关于自定义URI方案删除了​​“井号"前的空格. (#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆