bug 44272 : make escape/unescape (in DOM) correctly work with the full range of Unicode chars. (by making it use JSengine version) (r=brendan/bz, sr=bz)

This commit is contained in:
jshin%mailaps.org 2003-11-11 17:59:54 +00:00
Родитель 42f2669379
Коммит 339f3e4e20
4 изменённых файлов: 0 добавлений и 99 удалений

Просмотреть файл

@ -167,9 +167,6 @@ interface nsIDOMWindowInternal : nsIDOMWindow
// XXX Should this be in nsIDOMChromeWindow?
void updateCommands(in DOMString action);
DOMString escape(in DOMString str);
DOMString unescape(in DOMString str);
/* See nsIDOMJSWindow for the scriptable version of find()
* @param str: the search pattern
* @param caseSensitive: is the search caseSensitive

Просмотреть файл

@ -3604,96 +3604,6 @@ GlobalWindowImpl::GetBlurSuppression()
return suppress;
}
NS_IMETHODIMP
GlobalWindowImpl::Escape(const nsAString& aStr,
nsAString& aReturn)
{
nsresult rv = NS_OK;
nsXPIDLCString dest;
rv = ConvertCharset(aStr, getter_Copies(dest));
if (NS_SUCCEEDED(rv)) {
// Escape the string
char *outBuf =
nsEscape(dest.get(), nsEscapeMask(url_XAlphas | url_XPAlphas | url_Path));
CopyASCIItoUCS2(nsDependentCString(outBuf), aReturn);
nsMemory::Free(outBuf);
}
return rv;
}
NS_IMETHODIMP
GlobalWindowImpl::Unescape(const nsAString& aStr,
nsAString& aReturn)
{
// To gracefully deal with encoding issues, we have to do the following:
// 1) Convert aStr into the document encoding.
// 2) Unescape the byte buffer
// 3) Convert the byte buffer back into Unicode.
aReturn.Truncate();
if (aStr.IsEmpty())
return NS_OK;
// encode
nsXPIDLCString encodedString;
nsresult rv = ConvertCharset(aStr, getter_Copies(encodedString));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICharsetConverterManager>
ccm(do_GetService(kCharsetConverterManagerCID));
NS_ENSURE_TRUE(ccm, NS_ERROR_NOT_AVAILABLE);
// Get the document character set; default to utf-8 if all else fails
nsCAutoString charset(NS_LITERAL_CSTRING("UTF-8"));
if (mDocument) {
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
if (doc)
charset = doc->GetDocumentCharacterSet();
}
// Get a decoder for the character set
nsCOMPtr<nsIUnicodeDecoder> decoder;
rv = ccm->GetUnicodeDecoderRaw(charset.get(),
getter_AddRefs(decoder));
NS_ENSURE_SUCCESS(rv, rv);
// Unescape
// We cast away the const here; after this point, do not attempt to
// access encodedString directly -- it exists only to properly
// release the data buffer!
char *encodedData = NS_CONST_CAST(char*, encodedString.get());
PRInt32 unescapedByteCount = nsUnescapeCount(encodedData);
// Allocate buffer to decode into
PRInt32 maxLength;
// Get the expected length of the result string
rv = decoder->GetMaxLength(encodedData, unescapedByteCount, &maxLength);
NS_ENSURE_SUCCESS(rv, rv);
// Allocate a buffer of the maximum length
PRUnichar *dest = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar) * maxLength);
NS_ENSURE_TRUE(dest, NS_ERROR_OUT_OF_MEMORY);
PRInt32 destLen = maxLength;
// Convert from character set to unicode
rv = decoder->Convert(encodedData, &unescapedByteCount, dest, &destLen);
if (NS_FAILED(rv)) {
nsMemory::Free(dest);
return rv;
}
aReturn.Assign(dest, destLen);
nsMemory::Free(dest);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetSelection(nsISelection** aSelection)
{

Просмотреть файл

@ -1231,11 +1231,8 @@ static JSStdName standard_class_names[] = {
{js_InitNumberClass, LAZILY_PINNED_ATOM(parseInt)},
/* String global functions. */
#ifndef MOZILLA_CLIENT
/* These two are predefined in a backward-compatible way by the DOM. */
{js_InitStringClass, LAZILY_PINNED_ATOM(escape)},
{js_InitStringClass, LAZILY_PINNED_ATOM(unescape)},
#endif
{js_InitStringClass, LAZILY_PINNED_ATOM(decodeURI)},
{js_InitStringClass, LAZILY_PINNED_ATOM(encodeURI)},
{js_InitStringClass, LAZILY_PINNED_ATOM(decodeURIComponent)},

Просмотреть файл

@ -473,11 +473,8 @@ const char js_decodeURIComponent_str[] = "decodeURIComponent";
const char js_encodeURIComponent_str[] = "encodeURIComponent";
static JSFunctionSpec string_functions[] = {
#ifndef MOZILLA_CLIENT
/* These two are predefined in a backward-compatible way by the DOM. */
{js_escape_str, js_str_escape, 1,0,0},
{js_unescape_str, str_unescape, 1,0,0},
#endif
#if JS_HAS_UNEVAL
{js_uneval_str, str_uneval, 1,0,0},
#endif