зеркало из https://github.com/mozilla/pjs.git
Added a function to unescape 8bit only, 7bit encoding support.
bug 161479, r=shanjian, sr=jst, a=dbaron.
This commit is contained in:
Родитель
d3b99dd34c
Коммит
3870c76efe
|
@ -63,4 +63,17 @@ interface nsITextToSubURI : nsISupports
|
|||
* or error code of nsIUnicodeDecoder in case of covnersion failure
|
||||
*/
|
||||
AString unEscapeURIForUI(in ACString aCharset, in AUTF8String aURIFragment);
|
||||
|
||||
/**
|
||||
* Unescapes only non ASCII characters in the given URI fragment
|
||||
* note: this method assumes the URI as UTF-8 and fallbacks to the given charset
|
||||
* in case the data is not UTF-8
|
||||
*
|
||||
* @param aCharset the charset to convert from
|
||||
* @param aURIFragment the URI (or URI fragment) to unescape
|
||||
* @return Unescaped aURIFragment converted to unicode
|
||||
* @throws NS_ERROR_UCONV_NOCONV when there is no decoder for aCharset
|
||||
* or error code of nsIUnicodeDecoder in case of covnersion failure
|
||||
*/
|
||||
AString unEscapeNonAsciiURI(in ACString aCharset, in AUTF8String aURIFragment);
|
||||
};
|
||||
|
|
|
@ -159,6 +159,16 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeAndConvert(
|
|||
return rv;
|
||||
}
|
||||
|
||||
static PRBool statefulCharset(const char *charset)
|
||||
{
|
||||
if (!nsCRT::strncasecmp(charset, "ISO-2022-", sizeof("ISO-2022-")-1) ||
|
||||
!nsCRT::strcasecmp(charset, "UTF-7") ||
|
||||
!nsCRT::strcasecmp(charset, "HZ-GB-2312"))
|
||||
return PR_TRUE;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult nsTextToSubURI::convertURItoUnicode(const nsAFlatCString &aCharset,
|
||||
const nsAFlatCString &aURI,
|
||||
PRBool aIRI,
|
||||
|
@ -166,12 +176,15 @@ nsresult nsTextToSubURI::convertURItoUnicode(const nsAFlatCString &aCharset,
|
|||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (IsASCII(aURI)) {
|
||||
// check for 7bit encoding the data may not be ASCII after we decode
|
||||
PRBool isStatefulCharset = statefulCharset(aCharset.get());
|
||||
|
||||
if (!isStatefulCharset && IsASCII(aURI)) {
|
||||
_retval.Assign(NS_ConvertASCIItoUCS2(aURI));
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (aIRI) {
|
||||
if (!isStatefulCharset && aIRI) {
|
||||
NS_ConvertUTF8toUCS2 ucs2(aURI);
|
||||
if (aURI.Equals(NS_ConvertUCS2toUTF8(ucs2))) {
|
||||
_retval.Assign(ucs2);
|
||||
|
@ -221,4 +234,15 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString & aCharset,
|
|||
return convertURItoUnicode(PromiseFlatCString(aCharset), unescapedSpec, PR_TRUE, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextToSubURI::UnEscapeNonAsciiURI(const nsACString & aCharset,
|
||||
const nsACString &aURIFragment,
|
||||
nsAString &_retval)
|
||||
{
|
||||
nsCAutoString unescapedSpec;
|
||||
NS_UnescapeURL(PromiseFlatCString(aURIFragment),
|
||||
esc_AlwaysCopy | esc_OnlyNonASCII, unescapedSpec);
|
||||
|
||||
return convertURItoUnicode(PromiseFlatCString(aCharset), unescapedSpec, PR_TRUE, _retval);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
Загрузка…
Ссылка в новой задаче