mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-02 12:32:55 +00:00
fixes bug 282270 (and bug 282520) "always show punycode by default" r=dbaron sr=dveditz a=dbaron
This commit is contained in:
parent
f039b720ce
commit
452a016da8
@ -553,6 +553,11 @@ pref("network.http.pipelining.maxrequests" , 4);
|
||||
// are handled. IDN requires a nsIIDNService implementation.
|
||||
pref("network.enableIDN", true);
|
||||
|
||||
// This preference, if true, causes all UTF-8 domain names to be normalized to
|
||||
// punycode. The intention is to allow UTF-8 domain names as input, but never
|
||||
// generate them from punycode.
|
||||
pref("network.IDN_show_punycode", true);
|
||||
|
||||
// This preference specifies a list of domains for which DNS lookups will be
|
||||
// IPv4 only. Works around broken DNS servers which can't handle IPv6 lookups
|
||||
// and/or allows the user to disable IPv6 on a per-domain basis. See bug 68796.
|
||||
|
@ -54,8 +54,9 @@ static const PRUint32 kMaxDNSNodeLen = 63;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define NS_NET_PREF_IDNTESTBED "network.IDN_testbed"
|
||||
#define NS_NET_PREF_IDNPREFIX "network.IDN_prefix"
|
||||
#define NS_NET_PREF_IDNTESTBED "network.IDN_testbed"
|
||||
#define NS_NET_PREF_IDNPREFIX "network.IDN_prefix"
|
||||
#define NS_NET_PREF_IDNSHOWPUNYCODE "network.IDN_show_punycode"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsIDNService
|
||||
@ -73,8 +74,9 @@ nsresult nsIDNService::Init()
|
||||
if (prefInternal) {
|
||||
prefInternal->AddObserver(NS_NET_PREF_IDNTESTBED, this, PR_TRUE);
|
||||
prefInternal->AddObserver(NS_NET_PREF_IDNPREFIX, this, PR_TRUE);
|
||||
prefInternal->AddObserver(NS_NET_PREF_IDNSHOWPUNYCODE, this, PR_TRUE);
|
||||
prefsChanged(prefInternal, nsnull);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -84,26 +86,32 @@ NS_IMETHODIMP nsIDNService::Observe(nsISupports *aSubject,
|
||||
{
|
||||
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch( do_QueryInterface(aSubject) );
|
||||
if (prefBranch) {
|
||||
// to support test environment which is a temporary testing environment
|
||||
// until IDN is actually deployed
|
||||
if (NS_LITERAL_STRING(NS_NET_PREF_IDNTESTBED).Equals(aData)) {
|
||||
PRBool val;
|
||||
if (NS_SUCCEEDED(prefBranch->GetBoolPref(NS_NET_PREF_IDNTESTBED, &val)))
|
||||
mMultilingualTestBed = val;
|
||||
}
|
||||
else if (NS_LITERAL_STRING(NS_NET_PREF_IDNPREFIX).Equals(aData)) {
|
||||
nsXPIDLCString prefix;
|
||||
nsresult rv = prefBranch->GetCharPref(NS_NET_PREF_IDNPREFIX, getter_Copies(prefix));
|
||||
if (NS_SUCCEEDED(rv) && prefix.Length() <= kACEPrefixLen)
|
||||
PL_strncpyz(nsIDNService::mACEPrefix, prefix.get(), kACEPrefixLen + 1);
|
||||
}
|
||||
}
|
||||
if (prefBranch)
|
||||
prefsChanged(prefBranch, aData);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsIDNService::prefsChanged(nsIPrefBranch *prefBranch, const PRUnichar *pref)
|
||||
{
|
||||
if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNTESTBED).Equals(pref)) {
|
||||
PRBool val;
|
||||
if (NS_SUCCEEDED(prefBranch->GetBoolPref(NS_NET_PREF_IDNTESTBED, &val)))
|
||||
mMultilingualTestBed = val;
|
||||
}
|
||||
if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNPREFIX).Equals(pref)) {
|
||||
nsXPIDLCString prefix;
|
||||
nsresult rv = prefBranch->GetCharPref(NS_NET_PREF_IDNPREFIX, getter_Copies(prefix));
|
||||
if (NS_SUCCEEDED(rv) && prefix.Length() <= kACEPrefixLen)
|
||||
PL_strncpyz(nsIDNService::mACEPrefix, prefix.get(), kACEPrefixLen + 1);
|
||||
}
|
||||
if (!pref || NS_LITERAL_STRING(NS_NET_PREF_IDNSHOWPUNYCODE).Equals(pref)) {
|
||||
PRBool val;
|
||||
if (NS_SUCCEEDED(prefBranch->GetBoolPref(NS_NET_PREF_IDNSHOWPUNYCODE, &val)))
|
||||
mShowPunycode = val;
|
||||
}
|
||||
}
|
||||
|
||||
nsIDNService::nsIDNService()
|
||||
{
|
||||
nsresult rv;
|
||||
@ -113,6 +121,7 @@ nsIDNService::nsIDNService()
|
||||
strcpy(mACEPrefix, kIDNSPrefix);
|
||||
|
||||
mMultilingualTestBed = PR_FALSE;
|
||||
mShowPunycode = PR_FALSE;
|
||||
|
||||
if (idn_success != idn_nameprep_create(NULL, &mNamePrepHandle))
|
||||
mNamePrepHandle = nsnull;
|
||||
@ -183,7 +192,7 @@ NS_IMETHODIMP nsIDNService::ConvertACEtoUTF8(const nsACString & input, nsACStrin
|
||||
// ToUnicode never fails. If any step fails, then the original input
|
||||
// sequence is returned immediately in that step.
|
||||
|
||||
if (!IsASCII(input)) {
|
||||
if (mShowPunycode || !IsASCII(input)) {
|
||||
_retval.Assign(input);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -246,8 +255,14 @@ NS_IMETHODIMP nsIDNService::Normalize(const nsACString & input, nsACString & out
|
||||
// protect against bogus input
|
||||
NS_ENSURE_TRUE(IsUTF8(input), NS_ERROR_UNEXPECTED);
|
||||
|
||||
if (mShowPunycode)
|
||||
return ConvertUTF8toACE(input, output);
|
||||
|
||||
NS_ConvertUTF8toUTF16 inUTF16(input);
|
||||
normalizeFullStops(inUTF16);
|
||||
|
||||
nsAutoString outUTF16;
|
||||
nsresult rv = stringPrep(NS_ConvertUTF8toUTF16(input), outUTF16);
|
||||
nsresult rv = stringPrep(inUTF16, outUTF16);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
CopyUTF16toUTF8(outUTF16, output);
|
||||
return rv;
|
||||
|
@ -46,6 +46,8 @@
|
||||
#include "nsIUnicodeNormalizer.h"
|
||||
#include "nsIDNKitInterface.h"
|
||||
|
||||
class nsIPrefBranch;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsIDNService
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -72,8 +74,10 @@ private:
|
||||
nsresult encodeToACE(const nsAString& in, nsACString& out);
|
||||
nsresult stringPrep(const nsAString& in, nsAString& out);
|
||||
nsresult decodeACE(const nsACString& in, nsACString& out);
|
||||
void prefsChanged(nsIPrefBranch *prefBranch, const PRUnichar *pref);
|
||||
|
||||
PRBool mMultilingualTestBed; // if true generates extra node for mulitlingual testbed
|
||||
PRBool mShowPunycode;
|
||||
idn_nameprep_t mNamePrepHandle;
|
||||
nsCOMPtr<nsIUnicodeNormalizer> mNormalizer;
|
||||
char mACEPrefix[kACEPrefixLen+1];
|
||||
|
Loading…
x
Reference in New Issue
Block a user