Firebase 动态 link 缩短器 api 将嵌入的所有(空格)%20 转换为(加号)+ link
Firebase dynamic link shortner api converts all (spaces) %20 to (plus) + in embeded link
我正在使用 firebase 动态 link 缩短器 api 来创建动态 links,在请求中我传递了 long link,其中包含具有消息的查询参数我想在我的应用程序中呈现。但是当我打开 short link(我得到了响应)时,long link 中传递的所有空格都转换为 +,我试图从 firebase 仪表板创建类似的 link 但得到相同的问题。
我使用了下面文档中给出的 api
https://firebase.google.com/docs/reference/dynamic-links/link-shortener
只要任何 +
符号跟在查询分隔符 ?
.
之后,浏览器就应该支持这种行为,并且本机应该支持这种行为
根据 RFC3986 specification, its obsoleted forms RF2396, RF1738 和多年来的许多相关更改,space 字符 (0x20
) 必须在 URI 中编码。
为了与所有方案兼容,必须将百分比编码为 %20
。
但是,具有 http:
或 https:
方案的 URI 的查询组件具有 Content-Type
的 application/x-www-form-urlencoded
。此内容类型指定 space 将被编码为 +
,保留字符将根据 URI 规范进行转义,非字母数字字符将被百分比编码为 %HH
.
所以本质上,这意味着 +
在具有 http
或 [=25= 方案的 URI 中的 ?
之后转换回 space ].
示例:
// URI of a Whosebug search for "RFC 3986"
"https://whosebug.com/search?q=RFC+3986" // ✔ (default used by Whosebug)
"https://whosebug.com/search?q=RFC%203986" // ✔
"https://whosebug.com/search?q=RFC 3986" // ✖ (prohibited character)
// URI of "C:\Program Files (x86)\Notepad++\notepad++.exe"
"file:///C:/Program%20Files%20(x86)/Notepad++\notepad++.exe" // ✔
"file:///C:/Program%20Files%20(x86)/Notepad%2B%2B\notepad%2B%2B.exe" // ✔ (verbose, but valid)
"file:///C:/Program Files (x86)/Notepad++\notepad++.exe" // ✖ (spaces must be encoded)
"file:///C:/Program+Files+(x86)/Notepad++\notepad++.exe" // ✖ (not found, `+` not decoded to space)
The purpose of reserved characters is to provide a set of delimiting characters that are distinguishable from other data within a URI. URIs that differ in the replacement of a reserved character with its corresponding percent-encoded octet are not equivalent. Percent-encoding a reserved character, or decoding a percent-encoded octet that corresponds to a reserved character, will change how the URI is interpreted by most applications. Thus, characters in the reserved set are protected from normalization and are therefore safe to be used by scheme-specific and producer-specific algorithms for delimiting data subcomponents within a URI.
由于上述声明,请务必注意许多 decodeURI
/decodeURIComponent
函数不会将 +
解码为 space。由您的代码添加对此的支持,例如 Google Closure Library 如何在解码前将它们换成 spaces:
/**
* URL-decodes the string. We need to specially handle '+'s because
* the javascript library doesn't convert them to spaces.
* @param {string} str The string to url decode.
* @return {string} The decoded {@code str}.
*/
goog.string.urlDecode = function(str) {
return decodeURIComponent(str.replace(/\+/g, ' '));
};
我正在使用 firebase 动态 link 缩短器 api 来创建动态 links,在请求中我传递了 long link,其中包含具有消息的查询参数我想在我的应用程序中呈现。但是当我打开 short link(我得到了响应)时,long link 中传递的所有空格都转换为 +,我试图从 firebase 仪表板创建类似的 link 但得到相同的问题。
我使用了下面文档中给出的 api https://firebase.google.com/docs/reference/dynamic-links/link-shortener
只要任何 +
符号跟在查询分隔符 ?
.
根据 RFC3986 specification, its obsoleted forms RF2396, RF1738 和多年来的许多相关更改,space 字符 (0x20
) 必须在 URI 中编码。
为了与所有方案兼容,必须将百分比编码为 %20
。
但是,具有 http:
或 https:
方案的 URI 的查询组件具有 Content-Type
的 application/x-www-form-urlencoded
。此内容类型指定 space 将被编码为 +
,保留字符将根据 URI 规范进行转义,非字母数字字符将被百分比编码为 %HH
.
所以本质上,这意味着 +
在具有 http
或 [=25= 方案的 URI 中的 ?
之后转换回 space ].
示例:
// URI of a Whosebug search for "RFC 3986"
"https://whosebug.com/search?q=RFC+3986" // ✔ (default used by Whosebug)
"https://whosebug.com/search?q=RFC%203986" // ✔
"https://whosebug.com/search?q=RFC 3986" // ✖ (prohibited character)
// URI of "C:\Program Files (x86)\Notepad++\notepad++.exe"
"file:///C:/Program%20Files%20(x86)/Notepad++\notepad++.exe" // ✔
"file:///C:/Program%20Files%20(x86)/Notepad%2B%2B\notepad%2B%2B.exe" // ✔ (verbose, but valid)
"file:///C:/Program Files (x86)/Notepad++\notepad++.exe" // ✖ (spaces must be encoded)
"file:///C:/Program+Files+(x86)/Notepad++\notepad++.exe" // ✖ (not found, `+` not decoded to space)
The purpose of reserved characters is to provide a set of delimiting characters that are distinguishable from other data within a URI. URIs that differ in the replacement of a reserved character with its corresponding percent-encoded octet are not equivalent. Percent-encoding a reserved character, or decoding a percent-encoded octet that corresponds to a reserved character, will change how the URI is interpreted by most applications. Thus, characters in the reserved set are protected from normalization and are therefore safe to be used by scheme-specific and producer-specific algorithms for delimiting data subcomponents within a URI.
由于上述声明,请务必注意许多 decodeURI
/decodeURIComponent
函数不会将 +
解码为 space。由您的代码添加对此的支持,例如 Google Closure Library 如何在解码前将它们换成 spaces:
/**
* URL-decodes the string. We need to specially handle '+'s because
* the javascript library doesn't convert them to spaces.
* @param {string} str The string to url decode.
* @return {string} The decoded {@code str}.
*/
goog.string.urlDecode = function(str) {
return decodeURIComponent(str.replace(/\+/g, ' '));
};