mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1680139 - Add the ability for unEscapeURIForUI to disable re-escaping IDN blocklisted characters. r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D134401
This commit is contained in:
parent
28706cdf1a
commit
a41588c2f6
@ -32,9 +32,17 @@ interface nsITextToSubURI : nsISupports
|
||||
* </ul>
|
||||
*
|
||||
* @param aURIFragment the URI (or URI fragment) to unescape
|
||||
* @param aDontEscape whether to escape IDN blocklisted characters
|
||||
* @return Unescaped aURIFragment converted to unicode
|
||||
*/
|
||||
AString unEscapeURIForUI(in AUTF8String aURIFragment);
|
||||
AString unEscapeURIForUI(in AUTF8String aURIFragment,
|
||||
[optional] in boolean aDontEscape);
|
||||
%{C++
|
||||
nsresult UnEscapeURIForUI(const nsACString& aURIFragment,
|
||||
nsAString& _retval) {
|
||||
return UnEscapeURIForUI(aURIFragment, false, _retval);
|
||||
}
|
||||
%}
|
||||
|
||||
/**
|
||||
* Unescapes only non ASCII characters in the given URI fragment
|
||||
|
@ -100,6 +100,7 @@ nsresult nsTextToSubURI::convertURItoUnicode(const nsCString& aCharset,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString& aURIFragment,
|
||||
bool aDontEscape,
|
||||
nsAString& _retval) {
|
||||
nsAutoCString unescapedSpec;
|
||||
// skip control octets (0x00 - 0x1f and 0x7f) when unescaping
|
||||
@ -114,6 +115,10 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString& aURIFragment,
|
||||
CopyUTF8toUTF16(aURIFragment, _retval);
|
||||
}
|
||||
|
||||
if (aDontEscape) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If there are any characters that are unsafe for URIs, reescape those.
|
||||
if (mIDNBlocklist.IsEmpty()) {
|
||||
mozilla::net::InitializeBlocklist(mIDNBlocklist);
|
||||
|
23
intl/uconv/tests/unit/test_unEscapeURIForUI.js
Normal file
23
intl/uconv/tests/unit/test_unEscapeURIForUI.js
Normal file
@ -0,0 +1,23 @@
|
||||
// Tests for nsITextToSubURI.unEscapeURIForUI
|
||||
function run_test() {
|
||||
// Tests whether incomplete multibyte sequences throw.
|
||||
const tests = [
|
||||
{
|
||||
input: "http://example.com/?p=%E3%80%82",
|
||||
//TODO: should be the same as input, bug 1248812
|
||||
expected: "http://example.com/?p=%u3002",
|
||||
},
|
||||
{
|
||||
input: "http://example.com/?name=%E3%80%82",
|
||||
dontEscape: true,
|
||||
expected: "http://example.com/?name=\u3002",
|
||||
},
|
||||
];
|
||||
|
||||
for (const t of tests) {
|
||||
Assert.equal(
|
||||
Services.textToSubURI.unEscapeURIForUI(t.input, t.dontEscape),
|
||||
t.expected
|
||||
);
|
||||
}
|
||||
}
|
@ -86,5 +86,6 @@ support-files =
|
||||
[test_encode_macintosh.js]
|
||||
[test_input_stream.js]
|
||||
[test_unEscapeNonAsciiURI.js]
|
||||
[test_unEscapeURIForUI.js]
|
||||
[test_unmapped.js]
|
||||
[test_utf8_illegals.js]
|
||||
|
Loading…
Reference in New Issue
Block a user