diff --git a/mozilla/content/html/document/src/nsMediaDocument.cpp b/mozilla/content/html/document/src/nsMediaDocument.cpp
index c9b5449f487..4c90eb36aa9 100644
--- a/mozilla/content/html/document/src/nsMediaDocument.cpp
+++ b/mozilla/content/html/document/src/nsMediaDocument.cpp
@@ -322,10 +322,11 @@ nsMediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
nsCOMPtr textToSubURI =
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
- rv = textToSubURI->UnEscapeURIForUI(docCharset, fileName, fileStr);
+ // UnEscapeURIForUI always succeeds
+ textToSubURI->UnEscapeURIForUI(docCharset, fileName, fileStr);
+ else
+ CopyUTF8toUTF16(fileName, fileStr);
}
- if (fileStr.IsEmpty())
- CopyUTF8toUTF16(fileName, fileStr);
}
diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp
index 73aa578e208..c06b967003c 100644
--- a/mozilla/docshell/base/nsDocShell.cpp
+++ b/mozilla/docshell/base/nsDocShell.cpp
@@ -2835,11 +2835,11 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI,
nsCOMPtr textToSubURI(
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv))
- rv = textToSubURI->UnEscapeURIForUI(charset, spec, formatStrs[0]);
- if (NS_FAILED(rv)) {
- CopyASCIItoUCS2(spec, formatStrs[0]);
- rv = NS_OK;
- }
+ // UnEscapeURIForUI always succeeds
+ textToSubURI->UnEscapeURIForUI(charset, spec, formatStrs[0]);
+ else
+ CopyUTF8toUTF16(spec, formatStrs[0]);
+ rv = NS_OK;
formatStrCount = 1;
error.AssignLiteral("fileNotFound");
}
diff --git a/mozilla/intl/uconv/idl/nsITextToSubURI.idl b/mozilla/intl/uconv/idl/nsITextToSubURI.idl
index 509921c3507..938cc46163f 100644
--- a/mozilla/intl/uconv/idl/nsITextToSubURI.idl
+++ b/mozilla/intl/uconv/idl/nsITextToSubURI.idl
@@ -52,14 +52,18 @@ interface nsITextToSubURI : nsISupports
/**
* Unescapes the given URI fragment (for UI purpose only)
- * note: escaping back the result unescaped string is not guaranteed to be
- * identical to the original escaped string
+ * Note:
+ *
+ * - escaping back the result (unescaped string) is not guaranteed to
+ * give the original escaped string
+ *
- In case of a conversion error, the URI fragment (escaped) is
+ * assumed to be in UTF-8 and converted to AString (UTF-16)
+ *
- Always succeeeds (callers don't need to do error checking)
+ *
*
* @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 unEscapeURIForUI(in ACString aCharset, in AUTF8String aURIFragment);
diff --git a/mozilla/intl/uconv/src/nsTextToSubURI.cpp b/mozilla/intl/uconv/src/nsTextToSubURI.cpp
index 1373a230149..af8879d57d6 100644
--- a/mozilla/intl/uconv/src/nsTextToSubURI.cpp
+++ b/mozilla/intl/uconv/src/nsTextToSubURI.cpp
@@ -230,7 +230,12 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeURIForUI(const nsACString & aCharset,
NS_UnescapeURL(PromiseFlatCString(aURIFragment),
esc_SkipControl | esc_AlwaysCopy, unescapedSpec);
- return convertURItoUnicode(PromiseFlatCString(aCharset), unescapedSpec, PR_TRUE, _retval);
+ // in case of failure, return escaped URI
+ if (NS_FAILED(convertURItoUnicode(
+ PromiseFlatCString(aCharset), unescapedSpec, PR_TRUE, _retval)))
+ // assume UTF-8 instead of ASCII because hostname (IDN) may be in UTF-8
+ CopyUTF8toUTF16(aURIFragment, _retval);
+ return NS_OK;
}
NS_IMETHODIMP nsTextToSubURI::UnEscapeNonAsciiURI(const nsACString & aCharset,