mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 11:58:55 +00:00
Fix LDAP autocomplete regression with CJK names by adding a separate pref for minimum length of CJK names to search with a different default (bug 101086). r=shanjian@netscape.com, sr=blizzard@mozilla.org, a=asa@mozilla.org
This commit is contained in:
parent
408739ce43
commit
5690900ccc
@ -716,7 +716,7 @@ function setupLdapAutocompleteSession()
|
||||
}
|
||||
LDAPSession.serverURL = serverURL;
|
||||
|
||||
// don't search on strings shorter than this
|
||||
// don't search on non-CJK strings shorter than this
|
||||
//
|
||||
try {
|
||||
LDAPSession.minStringLength = prefs.GetIntPref(
|
||||
@ -726,6 +726,16 @@ function setupLdapAutocompleteSession()
|
||||
// nsLDAPAutoCompleteSession use its default.
|
||||
}
|
||||
|
||||
// don't search on CJK strings shorter than this
|
||||
//
|
||||
try {
|
||||
LDAPSession.cjkMinStringLength = prefs.GetIntPref(
|
||||
autocompleteDirectory + ".autoComplete.cjkMinStringLength");
|
||||
} catch (ex) {
|
||||
// if this pref isn't there, no big deal. just let
|
||||
// nsLDAPAutoCompleteSession use its default.
|
||||
}
|
||||
|
||||
// we don't try/catch here, because if this fails, we're outta luck
|
||||
//
|
||||
var ldapFormatter = Components.classes[
|
||||
|
@ -72,15 +72,20 @@ interface nsILDAPAutoCompleteSession : nsIAutoCompleteSession {
|
||||
* Strings shorter than this will return |nsIAutoCompleteStatus::ignored|
|
||||
* rather than triggering a search. This allows browsers to be
|
||||
* configured to not search on substrings so short that they
|
||||
* aren't indexed by the LDAP server (such searches can use significantly
|
||||
* more server resources and return a very large number of entries).
|
||||
* As of this writing, the "@mozilla.org/autocompleteSession;1?type=ldap"
|
||||
* contractid uses a default of two, as this avoids unindexed searches
|
||||
* with at least one widely-deployed webserver.
|
||||
* aren't indexed by the LDAP server (such searches can use
|
||||
* significantly more server resources and return a very large
|
||||
* number of entries). cjkMinStringLength is used for CJK
|
||||
* languages, and minStringLength for everything else. As of this
|
||||
* writing, the "@mozilla.org/autocompleteSession;1?type=ldap"
|
||||
* contractid uses defaults of two and zero, respectively. This
|
||||
* avoids most unindexed searches with at least one widely-deployed
|
||||
* webserver, but allows CJK languages, where a single glyph can be an
|
||||
* an entire name to still get results.
|
||||
*
|
||||
* @exception NS_ERROR_NULL_POINTER NULL pointer passed to getter
|
||||
*/
|
||||
attribute unsigned long minStringLength;
|
||||
attribute unsigned long cjkMinStringLength;
|
||||
|
||||
/**
|
||||
* LDAP server to complete against, in ldap: URL format.
|
||||
|
@ -53,7 +53,8 @@ nsLDAPAutoCompleteSession::nsLDAPAutoCompleteSession() :
|
||||
mState(UNBOUND),
|
||||
mFilterTemplate(NS_LITERAL_STRING(
|
||||
"(|(cn=%v1*%v2-*)(mail=%v1*%v2-*)(sn=%v1*%v2-*))")),
|
||||
mMaxHits(100), mMinStringLength(2), mSearchAttrs(0), mSearchAttrsSize(0)
|
||||
mMaxHits(100), mMinStringLength(2), mCjkMinStringLength(0),
|
||||
mSearchAttrs(0), mSearchAttrsSize(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
@ -65,6 +66,8 @@ nsLDAPAutoCompleteSession::~nsLDAPAutoCompleteSession()
|
||||
}
|
||||
}
|
||||
|
||||
#define IS_CJK_CHAR_FOR_LDAP(u) (0x2e80 <= (u) && (u) <= 0xd7ff)
|
||||
|
||||
/* void onStartLookup (in wstring searchString, in nsIAutoCompleteResults previousSearchResult, in nsIAutoCompleteListener listener); */
|
||||
NS_IMETHODIMP
|
||||
nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString,
|
||||
@ -101,7 +104,10 @@ nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString,
|
||||
if (searchString[0] == 0 ||
|
||||
nsDependentString(searchString).FindChar(PRUnichar('@'), 0) !=
|
||||
kNotFound ||
|
||||
mMinStringLength && nsCRT::strlen(searchString) < mMinStringLength) {
|
||||
( !IS_CJK_CHAR_FOR_LDAP(searchString[0]) ?
|
||||
mMinStringLength && nsCRT::strlen(searchString) < mMinStringLength :
|
||||
mCjkMinStringLength && nsCRT::strlen(searchString) <
|
||||
mCjkMinStringLength ) ) {
|
||||
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::ignored, 0, mState);
|
||||
return NS_OK;
|
||||
@ -1261,6 +1267,25 @@ nsLDAPAutoCompleteSession::SetMinStringLength(PRUint32 aMinStringLength)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// attribute unsigned long cjkMinStringLength
|
||||
NS_IMETHODIMP
|
||||
nsLDAPAutoCompleteSession::GetCjkMinStringLength(PRUint32 *aCjkMinStringLength)
|
||||
{
|
||||
if (!aCjkMinStringLength) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aCjkMinStringLength = mCjkMinStringLength;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP
|
||||
nsLDAPAutoCompleteSession::SetCjkMinStringLength(PRUint32 aCjkMinStringLength)
|
||||
{
|
||||
mCjkMinStringLength = aCjkMinStringLength;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// check to see if the message returned is related to our current operation
|
||||
// if there is no current operation, it's not. :-)
|
||||
//
|
||||
|
@ -70,6 +70,7 @@ class nsLDAPAutoCompleteSession : public nsILDAPMessageListener,
|
||||
nsCOMPtr<nsILDAPURL> mServerURL; // URL for the directory to search
|
||||
PRInt32 mMaxHits; // return at most this many entries
|
||||
PRUint32 mMinStringLength; // strings < this size are ignored
|
||||
PRUint32 mCjkMinStringLength; // ignore CJK strings < this size
|
||||
char **mSearchAttrs; // outputFormat search attrs for SearchExt call
|
||||
PRUint32 mSearchAttrsSize; // size of above array
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user