Backed out 4 changesets (bug 722299) for B2G mochitest failures on a CLOSED TREE.

This commit is contained in:
Ryan VanderMeulen 2013-02-28 20:44:53 -05:00
parent 2c144420df
commit 2f8259daf4
8 changed files with 67 additions and 670 deletions

View File

@ -38,9 +38,20 @@ that in the future this test tests what it was intended to test (and, until
bug 414090 is fixed, that it doesn't break when the Greek TLD is
un-whitelisted).
After bug 722299, this test sets network.IDN.restriction_profile to
"ASCII" in order not to change the behaviour of non-whitelisted TLDs
-->
<div>
<h2>Whitelisted</h2>
<iframe name="idnKidWhitelist" src="http://sub1.παράδειγμα.δοκιμή/tests/dom/tests/mochitest/dom-level0/idn_child.html?idn-whitelist"></iframe>
<iframe name="punycodeKidWhitelist" src="http://sub1.παράδειγμα.δοκιμή/tests/dom/tests/mochitest/dom-level0/idn_child.html?punycode-whitelist"></iframe>
</div>
<div>
<h2>Not whitelisted</h2>
<iframe name="idnKidNoWhitelist" src="http://sub1.exämple.test/tests/dom/tests/mochitest/dom-level0/idn_child.html?idn-nowhitelist"></iframe>
<iframe name="punycodeKidNoWhitelist" src="http://sub1.exämple.test/tests/dom/tests/mochitest/dom-level0/idn_child.html?punycode-nowhitelist"></iframe>
</div>
<pre id="test">
<script class="testbody" type="application/javascript">
@ -50,8 +61,6 @@ var gotIDNNoWhitelist = false;
var gotPunycodeNoWhitelist = false;
var gotIDNWhitelist = false;
var gotPunycodeWhitelist = false;
var oldProfile = SpecialPowers.getCharPref("network.IDN.restriction_profile", "moderate");
SpecialPowers.setCharPref("network.IDN.restriction_profile", "ASCII");
var whitelistRegex =
new RegExp("^http://sub1\\.παράδειγμα\\.δοκιμή/tests/dom/tests/" +
@ -179,7 +188,6 @@ function run()
ok(gotPunycodeNoWhitelist,
"punycode no-whitelist message not received");
SpecialPowers.setCharPref("network.IDN.restriction_profile", oldProfile);
SimpleTest.finish();
}, 0);
}, 0);
@ -195,18 +203,5 @@ window.addEventListener("message", receiveMessage, false);
window.addEventListener("load", run, false);
</script>
</pre>
<div>
<h2>Whitelisted</h2>
<iframe name="idnKidWhitelist" src="http://sub1.παράδειγμα.δοκιμή/tests/dom/tests/mochitest/dom-level0/idn_child.html?idn-whitelist"></iframe>
<iframe name="punycodeKidWhitelist" src="http://sub1.παράδειγμα.δοκιμή/tests/dom/tests/mochitest/dom-level0/idn_child.html?punycode-whitelist"></iframe>
</div>
<div>
<h2>Not whitelisted</h2>
<iframe name="idnKidNoWhitelist" src="http://sub1.exämple.test/tests/dom/tests/mochitest/dom-level0/idn_child.html?idn-nowhitelist"></iframe>
<iframe name="punycodeKidNoWhitelist" src="http://sub1.exämple.test/tests/dom/tests/mochitest/dom-level0/idn_child.html?punycode-nowhitelist"></iframe>
</div>
</body>
</html>

View File

@ -14,17 +14,28 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=417075
<p id="display"></p>
<div id="content" style="display: none"></div>
<iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="sameDomain"></iframe>
<iframe src="http://example.com/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="otherDomain"></iframe>
<iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="otherDomainPort"></iframe>
<iframe src="ftp://mochi.test:27534/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="localNoExist"></iframe>
<iframe src="http://sub1.παράδειγμα.δοκιμή/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="idnKidWhitelist"></iframe>
<iframe src="http://sub1.exämple.test/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="idnKidNoWhitelist"></iframe>
<pre id="test">
<script class="testbody" type="application/javascript"><![CDATA[
/** Test for Bug 417075 **/
SimpleTest.waitForExplicitFinish();
// After bug 722299, set network.IDN.restriction_profile to "ASCII" in
// order not to change the behaviour of non-whitelisted TLDs
var oldProfile = SpecialPowers.getCharPref("network.IDN.restriction_profile", "moderate");
SpecialPowers.setCharPref("network.IDN.restriction_profile", "ASCII");
function errorCheck(i, called, error, actual)
{
ok(!called, "receiver should not have been called for test #" + i);
@ -522,7 +533,6 @@ function run()
{
allTests(function()
{
SpecialPowers.setCharPref("network.IDN.restriction_profile", oldProfile);
SimpleTest.finish();
});
});
@ -531,21 +541,5 @@ function run()
window.addEventListener("load", run, false);
]]></script>
</pre>
<iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="sameDomain"></iframe>
<iframe src="http://example.com/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="otherDomain"></iframe>
<iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="otherDomainPort"></iframe>
<iframe src="ftp://mochi.test:27534/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="localNoExist"></iframe>
<iframe src="http://sub1.παράδειγμα.δοκιμή/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="idnKidWhitelist"></iframe>
<iframe src="http://sub1.exämple.test/tests/dom/tests/mochitest/whatwg/postMessage_origin_helper.xhtml"
id="idnKidNoWhitelist"></iframe>
</body>
</html>

View File

@ -1050,22 +1050,12 @@ pref("network.enableIDN", true);
// generate them from punycode.
pref("network.IDN_show_punycode", false);
// If "network.IDN.use_whitelist" is set to true, TLDs with
// "network.IDN.whitelist.tld" explicitly set to true are treated as
// TLDs with "network.IDN.whitelist.tld" explicitly set to true are treated as
// IDN-safe. Otherwise, they're treated as unsafe and punycode will be used
// for displaying them in the UI (e.g. URL bar), unless they conform to one of
// the profiles specified in
// http://www.unicode.org/reports/tr36/proposed.html#Security_Levels_and_Alerts
// If "network.IDN.restriction_profile" is "high", the Highly Restrictive
// profile is used.
// If "network.IDN.restriction_profile" is "moderate", the Moderately
// Restrictive profile is used.
// In all other cases, the ASCII-Only profile is used.
// Note that these preferences are referred to ONLY when
// "network.IDN_show_punycode" is false. In other words, all IDNs will be shown
// in punycode if "network.IDN_show_punycode" is true.
pref("network.IDN.restriction_profile", "moderate");
pref("network.IDN.use_whitelist", true);
// for displaying them in the UI (e.g. URL bar). Note that these preferences
// are referred to ONLY when "network.IDN_show_punycode" is false. In other
// words, all IDNs will be shown in punycode if "network.IDN_show_punycode"
// is true.
// ccTLDs
pref("network.IDN.whitelist.ac", true);

View File

@ -7,9 +7,6 @@
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsUnicharUtils.h"
#include "nsUnicodeProperties.h"
#include "nsUnicodeScriptCodes.h"
#include "harfbuzz/hb.h"
#include "nsIServiceManager.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
@ -18,8 +15,6 @@
#include "punycode.h"
using namespace mozilla::unicode;
//-----------------------------------------------------------------------------
// RFC 1034 - 3.1. Name space specifications and terminology
static const uint32_t kMaxDNSNodeLen = 63;
@ -31,8 +26,6 @@ static const uint32_t kMaxDNSNodeLen = 63;
#define NS_NET_PREF_IDNBLACKLIST "network.IDN.blacklist_chars"
#define NS_NET_PREF_SHOWPUNYCODE "network.IDN_show_punycode"
#define NS_NET_PREF_IDNWHITELIST "network.IDN.whitelist."
#define NS_NET_PREF_IDNUSEWHITELIST "network.IDN.use_whitelist"
#define NS_NET_PREF_IDNRESTRICTION "network.IDN.restriction_profile"
inline bool isOnlySafeChars(const nsAFlatString& in,
const nsAFlatString& blacklist)
@ -63,8 +56,6 @@ nsresult nsIDNService::Init()
prefInternal->AddObserver(NS_NET_PREF_IDNPREFIX, this, true);
prefInternal->AddObserver(NS_NET_PREF_IDNBLACKLIST, this, true);
prefInternal->AddObserver(NS_NET_PREF_SHOWPUNYCODE, this, true);
prefInternal->AddObserver(NS_NET_PREF_IDNRESTRICTION, this, true);
prefInternal->AddObserver(NS_NET_PREF_IDNUSEWHITELIST, this, true);
prefsChanged(prefInternal, nullptr);
}
@ -111,26 +102,6 @@ void nsIDNService::prefsChanged(nsIPrefBranch *prefBranch, const PRUnichar *pref
if (NS_SUCCEEDED(prefBranch->GetBoolPref(NS_NET_PREF_SHOWPUNYCODE, &val)))
mShowPunycode = val;
}
if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNUSEWHITELIST).Equals(pref)) {
bool val;
if (NS_SUCCEEDED(prefBranch->GetBoolPref(NS_NET_PREF_IDNUSEWHITELIST,
&val)))
mIDNUseWhitelist = val;
}
if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNRESTRICTION).Equals(pref)) {
nsXPIDLCString profile;
if (NS_FAILED(prefBranch->GetCharPref(NS_NET_PREF_IDNRESTRICTION,
getter_Copies(profile)))) {
profile.Truncate();
}
if (profile.Equals(NS_LITERAL_CSTRING("moderate"))) {
mRestrictionProfile = eModeratelyRestrictiveProfile;
} else if (profile.Equals(NS_LITERAL_CSTRING("high"))) {
mRestrictionProfile = eHighlyRestrictiveProfile;
} else {
mRestrictionProfile = eASCIIOnlyProfile;
}
}
}
nsIDNService::nsIDNService()
@ -156,15 +127,10 @@ nsIDNService::~nsIDNService()
/* ACString ConvertUTF8toACE (in AUTF8String input); */
NS_IMETHODIMP nsIDNService::ConvertUTF8toACE(const nsACString & input, nsACString & ace)
{
return UTF8toACE(input, ace, true, true);
return UTF8toACE(input, ace, true);
}
nsresult nsIDNService::SelectiveUTF8toACE(const nsACString& input, nsACString& ace)
{
return UTF8toACE(input, ace, true, false);
}
nsresult nsIDNService::UTF8toACE(const nsACString & input, nsACString & ace, bool allowUnassigned, bool convertAllLabels)
nsresult nsIDNService::UTF8toACE(const nsACString & input, nsACString & ace, bool allowUnassigned)
{
nsresult rv;
NS_ConvertUTF8toUTF16 ustr(input);
@ -188,7 +154,7 @@ nsresult nsIDNService::UTF8toACE(const nsACString & input, nsACString & ace, boo
len++;
if (*start++ == (PRUnichar)'.') {
rv = stringPrepAndACE(Substring(ustr, offset, len - 1), encodedBuf,
allowUnassigned, convertAllLabels);
allowUnassigned);
NS_ENSURE_SUCCESS(rv, rv);
ace.Append(encodedBuf);
@ -204,7 +170,7 @@ nsresult nsIDNService::UTF8toACE(const nsACString & input, nsACString & ace, boo
// encode the last node if non ASCII
if (len) {
rv = stringPrepAndACE(Substring(ustr, offset, len), encodedBuf,
allowUnassigned, convertAllLabels);
allowUnassigned);
NS_ENSURE_SUCCESS(rv, rv);
ace.Append(encodedBuf);
@ -216,21 +182,21 @@ nsresult nsIDNService::UTF8toACE(const nsACString & input, nsACString & ace, boo
/* AUTF8String convertACEtoUTF8(in ACString input); */
NS_IMETHODIMP nsIDNService::ConvertACEtoUTF8(const nsACString & input, nsACString & _retval)
{
return ACEtoUTF8(input, _retval, true, true);
}
nsresult nsIDNService::SelectiveACEtoUTF8(const nsACString& input, nsACString& _retval)
{
return ACEtoUTF8(input, _retval, false, false);
return ACEtoUTF8(input, _retval, true);
}
nsresult nsIDNService::ACEtoUTF8(const nsACString & input, nsACString & _retval,
bool allowUnassigned, bool convertAllLabels)
bool allowUnassigned)
{
// RFC 3490 - 4.2 ToUnicode
// ToUnicode never fails. If any step fails, then the original input
// sequence is returned immediately in that step.
if (!IsASCII(input)) {
_retval.Assign(input);
return NS_OK;
}
uint32_t len = 0, offset = 0;
nsAutoCString decodedBuf;
@ -244,7 +210,7 @@ nsresult nsIDNService::ACEtoUTF8(const nsACString & input, nsACString & _retval,
len++;
if (*start++ == '.') {
if (NS_FAILED(decodeACE(Substring(input, offset, len - 1), decodedBuf,
allowUnassigned, convertAllLabels))) {
allowUnassigned))) {
_retval.Assign(input);
return NS_OK;
}
@ -258,7 +224,7 @@ nsresult nsIDNService::ACEtoUTF8(const nsACString & input, nsACString & _retval,
// decode the last node
if (len) {
if (NS_FAILED(decodeACE(Substring(input, offset, len), decodedBuf,
allowUnassigned, convertAllLabels)))
allowUnassigned)))
_retval.Assign(input);
else
_retval.Append(decodedBuf);
@ -335,29 +301,20 @@ NS_IMETHODIMP nsIDNService::ConvertToDisplayIDN(const nsACString & input, bool *
// If host is ACE, then convert to UTF-8 if the host is in the IDN whitelist.
// Else, if host is already UTF-8, then make sure it is normalized per IDN.
nsresult rv = NS_OK;
// Even if the hostname is not ASCII, individual labels may still be ACE, so
// test IsACE before testing IsASCII
bool isACE;
IsACE(input, &isACE);
nsresult rv;
if (IsASCII(input)) {
// first, canonicalize the host to lowercase, for whitelist lookup
_retval = input;
ToLowerCase(_retval);
if (isACE && !mShowPunycode) {
bool isACE;
IsACE(_retval, &isACE);
if (isACE && !mShowPunycode && isInWhitelist(_retval)) {
// ACEtoUTF8() can't fail, but might return the original ACE string
nsAutoCString temp(_retval);
if (isInWhitelist(temp)) {
// If the domain is in the whitelist, return the host in UTF-8
ACEtoUTF8(temp, _retval, false, true);
} else {
// Otherwise convert from ACE to UTF8 only those labels which are
// considered safe for display
SelectiveACEtoUTF8(temp, _retval);
}
ACEtoUTF8(temp, _retval, false);
*_isASCII = IsASCII(_retval);
} else {
*_isASCII = true;
@ -366,16 +323,7 @@ NS_IMETHODIMP nsIDNService::ConvertToDisplayIDN(const nsACString & input, bool *
// We have to normalize the hostname before testing against the domain
// whitelist (see bug 315411), and to ensure the entire string gets
// normalized.
//
// Normalization and the tests for safe display below, assume that the
// input is Unicode, so first convert any ACE labels to UTF8
if (isACE) {
nsAutoCString temp;
ACEtoUTF8(input, temp, false, true);
rv = Normalize(temp, _retval);
} else {
rv = Normalize(input, _retval);
}
rv = Normalize(input, _retval);
if (NS_FAILED(rv)) return rv;
if (mShowPunycode && NS_SUCCEEDED(ConvertUTF8toACE(_retval, _retval))) {
@ -388,12 +336,8 @@ NS_IMETHODIMP nsIDNService::ConvertToDisplayIDN(const nsACString & input, bool *
// unsafe characters, so leave it ACE encoded. see bug 283016, bug 301694, and bug 309311.
*_isASCII = IsASCII(_retval);
if (!*_isASCII && !isInWhitelist(_retval)) {
// SelectiveUTF8toACE may return a domain name where some labels are in UTF-8
// and some are in ACE, depending on whether they are considered safe for
// display
rv = SelectiveUTF8toACE(_retval, _retval);
*_isASCII = IsASCII(_retval);
return rv;
*_isASCII = true;
return ConvertUTF8toACE(_retval, _retval);
}
}
@ -598,8 +542,7 @@ nsresult nsIDNService::encodeToACE(const nsAString& in, nsACString& out)
}
nsresult nsIDNService::stringPrepAndACE(const nsAString& in, nsACString& out,
bool allowUnassigned,
bool convertAllLabels)
bool allowUnassigned)
{
nsresult rv = NS_OK;
@ -612,8 +555,6 @@ nsresult nsIDNService::stringPrepAndACE(const nsAString& in, nsACString& out,
if (IsASCII(in))
LossyCopyUTF16toASCII(in, out);
else if (!convertAllLabels && isLabelSafe(in))
CopyUTF16toUTF8(in, out);
else {
nsAutoString strPrep;
rv = stringPrep(in, strPrep, allowUnassigned);
@ -662,7 +603,7 @@ void nsIDNService::normalizeFullStops(nsAString& s)
}
nsresult nsIDNService::decodeACE(const nsACString& in, nsACString& out,
bool allowUnassigned, bool convertAllLabels)
bool allowUnassigned)
{
bool isAce;
IsACE(in, &isAce);
@ -692,17 +633,13 @@ nsresult nsIDNService::decodeACE(const nsACString& in, nsACString& out,
nsAutoString utf16;
ucs4toUtf16(output, utf16);
delete [] output;
if (!convertAllLabels && !isLabelSafe(utf16)) {
out.Assign(in);
return NS_OK;
}
if (!isOnlySafeChars(utf16, mIDNBlacklist))
return NS_ERROR_FAILURE;
CopyUTF16toUTF8(utf16, out);
// Validation: encode back to ACE and compare the strings
nsAutoCString ace;
nsresult rv = UTF8toACE(out, ace, allowUnassigned, true);
nsresult rv = UTF8toACE(out, ace, allowUnassigned);
NS_ENSURE_SUCCESS(rv, rv);
if (!ace.Equals(in, nsCaseInsensitiveCStringComparator()))
@ -713,11 +650,11 @@ nsresult nsIDNService::decodeACE(const nsACString& in, nsACString& out,
bool nsIDNService::isInWhitelist(const nsACString &host)
{
if (mIDNUseWhitelist && mIDNWhitelistPrefBranch) {
if (mIDNWhitelistPrefBranch) {
nsAutoCString tld(host);
// make sure the host is ACE for lookup and check that there are no
// unassigned codepoints
if (!IsASCII(tld) && NS_FAILED(UTF8toACE(tld, tld, false, true))) {
if (!IsASCII(tld) && NS_FAILED(UTF8toACE(tld, tld, false))) {
return false;
}
@ -737,173 +674,3 @@ bool nsIDNService::isInWhitelist(const nsACString &host)
return false;
}
bool nsIDNService::isLabelSafe(const nsAString &label)
{
// We should never get here if the label is ASCII
NS_ASSERTION(!IsASCII(label), "ASCII label in IDN checking");
if (mRestrictionProfile == eASCIIOnlyProfile) {
return false;
}
nsAString::const_iterator current, end;
label.BeginReading(current);
label.EndReading(end);
int32_t lastScript = MOZ_SCRIPT_INVALID;
uint32_t previousChar = 0;
uint32_t savedNumberingSystem = 0;
HanVariantType savedHanVariant = HVT_NotHan;
int32_t savedScript = -1;
while (current != end) {
uint32_t ch = *current++;
if (NS_IS_HIGH_SURROGATE(ch) && current != end &&
NS_IS_LOW_SURROGATE(*current)) {
ch = SURROGATE_TO_UCS4(ch, *current++);
}
// Check for restricted characters; aspirational scripts are permitted
XidmodType xm = GetIdentifierModification(ch);
int32_t script = GetScriptCode(ch);
if (xm > XIDMOD_RECOMMENDED &&
!(xm == XIDMOD_LIMITED_USE &&
(script == MOZ_SCRIPT_CANADIAN_ABORIGINAL ||
script == MOZ_SCRIPT_MIAO ||
script == MOZ_SCRIPT_MONGOLIAN ||
script == MOZ_SCRIPT_TIFINAGH ||
script == MOZ_SCRIPT_YI))) {
return false;
}
// Check for mixed script
if (script != MOZ_SCRIPT_COMMON &&
script != MOZ_SCRIPT_INHERITED &&
script != lastScript) {
if (illegalScriptCombo(script, savedScript)) {
return false;
}
lastScript = script;
}
// Check for mixed numbering systems
if (GetGeneralCategory(ch) ==
HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER) {
uint32_t zeroCharacter = ch - GetNumericValue(ch);
if (savedNumberingSystem == 0) {
// If we encounter a decimal number, save the zero character from that
// numbering system.
savedNumberingSystem = zeroCharacter;
} else if (zeroCharacter != savedNumberingSystem) {
return false;
}
}
// Check for consecutive non-spacing marks
if (previousChar != 0 &&
previousChar == ch &&
GetGeneralCategory(ch) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) {
return false;
}
// Check for both simplified-only and traditional-only Chinese characters
HanVariantType hanVariant = GetHanVariant(ch);
if (hanVariant == HVT_SimplifiedOnly || hanVariant == HVT_TraditionalOnly) {
if (savedHanVariant == HVT_NotHan) {
savedHanVariant = hanVariant;
} else if (hanVariant != savedHanVariant) {
return false;
}
}
previousChar = ch;
}
return true;
}
// Scripts that we care about in illegalScriptCombo
static const int32_t scriptTable[] = {
MOZ_SCRIPT_BOPOMOFO, MOZ_SCRIPT_CYRILLIC, MOZ_SCRIPT_GREEK,
MOZ_SCRIPT_HANGUL, MOZ_SCRIPT_HAN, MOZ_SCRIPT_HIRAGANA,
MOZ_SCRIPT_KATAKANA, MOZ_SCRIPT_LATIN };
#define BOPO 0
#define CYRL 1
#define GREK 2
#define HANG 3
#define HANI 4
#define HIRA 5
#define KATA 6
#define LATN 7
#define OTHR 8
#define JPAN 9 // Latin + Han + Hiragana + Katakana
#define CHNA 10 // Latin + Han + Bopomofo
#define KORE 11 // Latin + Han + Hangul
#define HNLT 12 // Latin + Han (could be any of the above combinations)
#define FAIL 13
static inline int32_t findScriptIndex(int32_t aScript)
{
int32_t tableLength = sizeof(scriptTable) / sizeof(int32_t);
for (int32_t index = 0; index < tableLength; ++index) {
if (aScript == scriptTable[index]) {
return index;
}
}
return OTHR;
}
static const int32_t scriptComboTable[13][9] = {
/* thisScript: BOPO CYRL GREK HANG HANI HIRA KATA LATN OTHR
* savedScript */
/* BOPO */ { BOPO, FAIL, FAIL, FAIL, CHNA, FAIL, FAIL, CHNA, FAIL },
/* CYRL */ { FAIL, CYRL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL },
/* GREK */ { FAIL, FAIL, GREK, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL },
/* HANG */ { FAIL, FAIL, FAIL, HANG, KORE, FAIL, FAIL, KORE, FAIL },
/* HANI */ { CHNA, FAIL, FAIL, KORE, HANI, JPAN, JPAN, HNLT, FAIL },
/* HIRA */ { FAIL, FAIL, FAIL, FAIL, JPAN, HIRA, JPAN, JPAN, FAIL },
/* KATA */ { FAIL, FAIL, FAIL, FAIL, JPAN, JPAN, KATA, JPAN, FAIL },
/* LATN */ { CHNA, FAIL, FAIL, KORE, HNLT, JPAN, JPAN, LATN, OTHR },
/* OTHR */ { FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, OTHR, FAIL },
/* JPAN */ { FAIL, FAIL, FAIL, FAIL, JPAN, JPAN, JPAN, JPAN, FAIL },
/* CHNA */ { CHNA, FAIL, FAIL, FAIL, CHNA, FAIL, FAIL, CHNA, FAIL },
/* KORE */ { FAIL, FAIL, FAIL, KORE, KORE, FAIL, FAIL, KORE, FAIL },
/* HNLT */ { CHNA, FAIL, FAIL, KORE, HNLT, JPAN, JPAN, HNLT, FAIL }
};
bool nsIDNService::illegalScriptCombo(int32_t script, int32_t& savedScript)
{
if (savedScript == -1) {
savedScript = findScriptIndex(script);
return false;
}
savedScript = scriptComboTable[savedScript] [findScriptIndex(script)];
/*
* Special case combinations that depend on which profile is in use
* In the Highly Restrictive profile Latin is not allowed with any
* other script
*
* In the Moderately Restrictive profile Latin mixed with any other
* single script is allowed.
*/
return ((savedScript == OTHR &&
mRestrictionProfile == eHighlyRestrictiveProfile) ||
savedScript == FAIL);
}
#undef BOPO
#undef CYRL
#undef GREK
#undef HANG
#undef HANI
#undef HIRA
#undef KATA
#undef LATN
#undef OTHR
#undef JPAN
#undef CHNA
#undef KORE
#undef HNLT
#undef FAIL

View File

@ -39,22 +39,18 @@ public:
private:
void normalizeFullStops(nsAString& s);
nsresult stringPrepAndACE(const nsAString& in, nsACString& out,
bool allowUnassigned, bool convertAllLabels);
bool allowUnassigned);
nsresult encodeToACE(const nsAString& in, nsACString& out);
nsresult stringPrep(const nsAString& in, nsAString& out,
bool allowUnassigned);
nsresult decodeACE(const nsACString& in, nsACString& out,
bool allowUnassigned, bool convertAllLabels);
nsresult SelectiveUTF8toACE(const nsACString& input, nsACString& ace);
nsresult SelectiveACEtoUTF8(const nsACString& input, nsACString& _retval);
nsresult UTF8toACE(const nsACString& input, nsACString& ace,
bool allowUnassigned, bool convertAllLabels);
nsresult ACEtoUTF8(const nsACString& input, nsACString& _retval,
bool allowUnassigned, bool convertAllLabels);
bool allowUnassigned);
nsresult UTF8toACE(const nsACString& in, nsACString& out,
bool allowUnassigned);
nsresult ACEtoUTF8(const nsACString& in, nsACString& out,
bool allowUnassigned);
bool isInWhitelist(const nsACString &host);
void prefsChanged(nsIPrefBranch *prefBranch, const PRUnichar *pref);
bool isLabelSafe(const nsAString &label);
bool illegalScriptCombo(int32_t script, int32_t& savedScript);
bool mMultilingualTestBed; // if true generates extra node for multilingual testbed
idn_nameprep_t mNamePrepHandle;
@ -62,14 +58,7 @@ private:
char mACEPrefix[kACEPrefixLen+1];
nsXPIDLString mIDNBlacklist;
bool mShowPunycode;
enum restrictionProfile {
eASCIIOnlyProfile,
eHighlyRestrictiveProfile,
eModeratelyRestrictiveProfile
};
restrictionProfile mRestrictionProfile;
nsCOMPtr<nsIPrefBranch> mIDNWhitelistPrefBranch;
bool mIDNUseWhitelist;
};
#endif // nsIDNService_h__

View File

@ -1,329 +0,0 @@
// Test algorithm for unicode display of IDNA URL (bug 722299)
const testcases = [
// Original Punycode or Expected UTF-8 by profile
// URL normalized form ASCII-Only, High, Moderate
//
// Latin script
["cuillère", "xn--cuillre-6xa", false, true, true],
// repeated non-spacing marks
["gruz̀̀ere", "xn--gruzere-ogea", false, false, false],
// non-XID character
["I♥NY", "xn--iny-zx5a", false, false, false],
// Cyrillic alone
["толсто́й", "xn--lsa83dealbred", false, true, true],
// Mixed script Cyrillic/Latin
["толсто́й-in-Russian",
"xn---in-russian-1jg071b0a8bb4cpd", false, false, false],
// Mixed script Latin/Cyrillic
["war-and-миръ", "xn--war-and--b9g3b7b3h", false, false, false],
// Cherokee (Restricted script)
["ᏣᎳᎩ", "xn--f9dt7l", false, false, false],
// Yi (Aspirational script)
["ꆈꌠꁱꂷ", "xn--4o7a6e1x64c", false, true, true],
// Greek alone
["πλάτων", "xn--hxa3ahjw4a", false, true, true],
// Mixed script Greek/Latin
["πλάτωνicrelationship",
"xn--icrelationship-96j4t9a3cwe2e", false, false, false],
// Mixed script Latin/Greek
["spaceὈδύσσεια", "xn--space-h9dui0b0ga2j1562b", false, false, false],
// Devanagari alone
["मराठी", "xn--d2b1ag0dl", false, true, true],
// Devanagari with Armenian
["मराठीՀայաստան",
"xn--y9aaa1d0ai1cq964f8dwa2o1a", false, false, false],
// Devanagari with common
["मराठी123", "xn--123-mhh3em2hra", false, true, true],
// Common with Devanagari
["123मराठी", "xn--123-phh3em2hra", false, true, true],
// Latin with Han
["chairman毛",
"xn--chairman-k65r", false, true, true],
// Han with Latin
["山葵sauce", "xn--sauce-6j9ii40v", false, true, true],
// Latin with Han, Hiragana and Katakana
["van語ではドイ", "xn--van-ub4bpb6w0in486d", false, true, true],
// Latin with Han, Katakana and Hiragana
["van語ドイでは", "xn--van-ub4bpb4w0ip486d", false, true, true],
// Latin with Hiragana, Han and Katakana
["vanでは語ドイ", "xn--van-ub4bpb6w0ip486d", false, true, true],
// Latin with Hiragana, Katakana and Han
["vanではドイ語", "xn--van-ub4bpb6w0ir486d", false, true, true],
// Latin with Katakana, Han and Hiragana
["vanドイ語では", "xn--van-ub4bpb4w0ir486d", false, true, true],
// Latin with Katakana, Hiragana and Han
["vanドイでは語", "xn--van-ub4bpb4w0it486d", false, true, true],
// Han with Latin, Hiragana and Katakana
["語vanではドイ", "xn--van-ub4bpb6w0ik486d", false, true, true],
// Han with Latin, Katakana and Hiragana
["語vanドイでは", "xn--van-ub4bpb4w0im486d", false, true, true],
// Han with Hiragana, Latin and Katakana
["語ではvanドイ", "xn--van-rb4bpb9w0ik486d", false, true, true],
// Han with Hiragana, Katakana and Latin
["語ではドイvan", "xn--van-rb4bpb6w0in486d", false, true, true],
// Han with Katakana, Latin and Hiragana
["語ドイvanでは", "xn--van-ub4bpb1w0ip486d", false, true, true],
// Han with Katakana, Hiragana and Latin
["語ドイではvan", "xn--van-rb4bpb4w0ip486d", false, true, true],
// Hiragana with Latin, Han and Katakana
["イツvan語ではド", "xn--van-ub4bpb1wvhsbx330n", false, true, true],
// Hiragana with Latin, Katakana and Han
["ではvanドイ語", "xn--van-rb4bpb9w0ir486d", false, true, true],
// Hiragana with Han, Latin and Katakana
["では語vanドイ", "xn--van-rb4bpb9w0im486d", false, true, true],
// Hiragana with Han, Katakana and Latin
["では語ドイvan", "xn--van-rb4bpb6w0ip486d", false, true, true],
// Hiragana with Katakana, Latin and Han
["ではドイvan語", "xn--van-rb4bpb6w0iu486d", false, true, true],
// Hiragana with Katakana, Han and Latin
["ではドイ語van", "xn--van-rb4bpb6w0ir486d", false, true, true],
// Katakana with Latin, Han and Hiragana
["ドイvan語では", "xn--van-ub4bpb1w0iu486d", false, true, true],
// Katakana with Latin, Hiragana and Han
["ドイvanでは語", "xn--van-ub4bpb1w0iw486d", false, true, true],
// Katakana with Han, Latin and Hiragana
["ドイ語vanでは", "xn--van-ub4bpb1w0ir486d", false, true, true],
// Katakana with Han, Hiragana and Latin
["ドイ語ではvan", "xn--van-rb4bpb4w0ir486d", false, true, true],
// Katakana with Hiragana, Latin and Han
["ドイではvan語", "xn--van-rb4bpb4w0iw486d", false, true, true],
// Katakana with Hiragana, Han and Latin
["ドイでは語van", "xn--van-rb4bpb4w0it486d", false, true, true],
// Han with common
["中国123", "xn--123-u68dy61b", false, true, true],
// common with Han
["123中国", "xn--123-x68dy61b", false, true, true],
// Characters that normalize to permitted characters
// (also tests Plane 1 supplementary characters)
["super𝟖", "super8", true, true, true],
// Han from Plane 2
["𠀀𠀁𠀂", "xn--j50icd", false, true, true],
// Han from Plane 2 with js (UTF-16) escapes
["\uD840\uDC00\uD840\uDC01\uD840\uDC02",
"xn--j50icd", false, true, true],
// Same with a lone high surrogate at the end
["\uD840\uDC00\uD840\uDC01\uD840", "", false, false, false],
// Latin text and Bengali digits
["super", "xn--super-k2l", false, false, true],
// Bengali digits and Latin text
["৫ab", "xn--ab-x5f", false, false, true],
// Bengali text and Latin digits
["অঙ্কুর8", "xn--8-70d2cp0j6dtd", false, true, true],
// Latin digits and Bengali text
["5াব", "xn--5-h3d7c", false, true, true],
// Mixed numbering systems
["٢٠۰٠", "xn--8hbae38c", false, false, false],
// Traditional Chinese
["萬城", "xn--uis754h", false, true, true],
// Simplified Chinese
["万城", "xn--chq31v", false, true, true],
// Simplified-only and Traditional-only Chinese in the same label
["万萬城", "xn--chq31vsl1b", false, false, false],
// Traditional-only and Simplified-only Chinese in the same label
["萬万城", "xn--chq31vrl1b", false, false, false],
// Han and Latin and Bopomofo
["注音符号bopomofoㄅㄆㄇㄈ",
"xn--bopomofo-hj5gkalm1637i876cuw0brk5f",
false, true, true],
// Han, bopomofo, Latin
["注音符号ㄅㄆㄇㄈbopomofo",
"xn--bopomofo-8i5gkalm9637i876cuw0brk5f",
false, true, true],
// Latin, Han, Bopomofo
["bopomofo注音符号ㄅㄆㄇㄈ",
"xn--bopomofo-hj5gkalm9637i876cuw0brk5f",
false, true, true],
// Latin, Bopomofo, Han
["bopomofoㄅㄆㄇㄈ注音符号",
"xn--bopomofo-hj5gkalm3737i876cuw0brk5f",
false, true, true],
// Bopomofo, Han, Latin
["ㄅㄆㄇㄈ注音符号bopomofo",
"xn--bopomofo-8i5gkalm3737i876cuw0brk5f",
false, true, true],
// Bopomofo, Latin, Han
["ㄅㄆㄇㄈbopomofo注音符号",
"xn--bopomofo-8i5gkalm1837i876cuw0brk5f",
false, true, true],
// Han, bopomofo and katakana
["注音符号ㄅㄆㄇㄈボポモフォ",
"xn--jckteuaez1shij0450gylvccz9asi4e",
false, false, false],
// Han, katakana, bopomofo
["注音符号ボポモフォㄅㄆㄇㄈ",
"xn--jckteuaez6shij5350gylvccz9asi4e",
false, false, false],
// bopomofo, han, katakana
["ㄅㄆㄇㄈ注音符号ボポモフォ",
"xn--jckteuaez1shij4450gylvccz9asi4e",
false, false, false],
// bopomofo, katakana, han
["ㄅㄆㄇㄈボポモフォ注音符号",
"xn--jckteuaez1shij9450gylvccz9asi4e",
false, false, false],
// katakana, Han, bopomofo
["ボポモフォ注音符号ㄅㄆㄇㄈ",
"xn--jckteuaez6shij0450gylvccz9asi4e",
false, false, false],
// katakana, bopomofo, Han
["ボポモフォㄅㄆㄇㄈ注音符号",
"xn--jckteuaez6shij4450gylvccz9asi4e",
false, false, false],
// Han, Hangul and Latin
["韓한글hangul",
"xn--hangul-2m5ti09k79ze", false, true, true],
// Han, Latin and Hangul
["韓hangul한글",
"xn--hangul-2m5to09k79ze", false, true, true],
// Hangul, Han and Latin
["한글韓hangul",
"xn--hangul-2m5th09k79ze", false, true, true],
// Hangul, Latin and Han
["한글hangul韓",
"xn--hangul-8m5t898k79ze", false, true, true],
// Latin, Han and Hangul
["hangul韓한글",
"xn--hangul-8m5ti09k79ze", false, true, true],
// Latin, Hangul and Han
["hangul한글韓",
"xn--hangul-8m5th09k79ze", false, true, true],
// Hangul and katakana
["한글ハングル",
"xn--qck1c2d4a9266lkmzb", false, false, false],
// Katakana and Hangul
["ハングル한글",
"xn--qck1c2d4a2366lkmzb", false, false, false]
];
const profiles = ["ASCII", "high", "moderate"];
const Cc = Components.classes;
const Ci = Components.interfaces;
function run_test() {
var pbi = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
var oldProfile = pbi.getCharPref("network.IDN.restriction_profile", "moderate");
var oldWhiteListCom;
try {
oldWhitelistCom = pbi.getBoolPref("network.IDN.whitelist.com");
} catch(e) {
oldWhitelistCom = false;
}
var idnService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
for (var i = 0; i < profiles.length; ++i) {
pbi.setCharPref("network.IDN.restriction_profile", profiles[i]);
pbi.setBoolPref("network.IDN.whitelist.com", false);
dump("testing " + profiles[i] + " profile");
for (var j = 0; j < testcases.length; ++j) {
var test = testcases[j];
var URL = test[0] + ".com";
var punycodeURL = test[1] + ".com";
var expectedUnicode = test[2 + i];
var isASCII = {};
var result;
try {
result = idnService.convertToDisplayIDN(URL, isASCII);
} catch(e) {
result = ".com";
}
if (punycodeURL.substr(0, 4) == "xn--") {
// test convertToDisplayIDN with a Unicode URL and with a
// Punycode URL if we have one
do_check_eq(escape(result),
expectedUnicode ? escape(URL) : escape(punycodeURL));
result = idnService.convertToDisplayIDN(punycodeURL, isASCII);
do_check_eq(escape(result),
expectedUnicode ? escape(URL) : escape(punycodeURL));
} else {
// The "punycode" URL isn't punycode. This happens in testcases
// where the Unicode URL has become normalized to an ASCII URL,
// so, even though expectedUnicode is true, the expected result
// is equal to punycodeURL
do_check_eq(escape(result), escape(punycodeURL));
}
}
}
pbi.setBoolPref("network.IDN.whitelist.com", oldWhitelistCom);
pbi.setCharPref("network.IDN.restriction_profile", oldProfile);
}

View File

@ -28,11 +28,6 @@ function run_test() {
.getService(Components.interfaces.nsIPrefBranch);
pbi.setBoolPref("network.IDN.whitelist.es", true);
// After bug 722299, set network.IDN.restriction_profile to "ASCII" in
// order not to change the behaviour of non-whitelisted TLDs
var oldProfile = pbi.getCharPref("network.IDN.restriction_profile", "moderate");
pbi.setCharPref("network.IDN.restriction_profile", "ASCII");
// check convertToDisplayIDN against the whitelist
var isASCII = {};
do_check_eq(idnService.convertToDisplayIDN("b\u00FCcher.es", isASCII), "b\u00FCcher.es");
@ -50,7 +45,4 @@ function run_test() {
do_check_eq(isASCII.value, false);
do_check_eq(idnService.convertToDisplayIDN("test.xn--k-dha", isASCII), "test.\u00FCk");
do_check_eq(isASCII.value, false);
// reset pref to default
pbi.setCharPref("network.IDN.restriction_profile", oldProfile);
}

View File

@ -91,7 +91,6 @@ fail-if = os == "android"
[test_bug667818.js]
[test_bug669001.js]
[test_bug712914_secinfo_validation.js]
[test_bug722299.js]
[test_bug770243.js]
[test_doomentry.js]
[test_cacheflags.js]