Bug 1193625 - Fallback to ASCII if AutoConfig UTF-8 conversion fails. r=Mossop, mrbkap

This commit is contained in:
Mike Kaply 2015-09-28 08:04:47 -05:00
parent d969325380
commit 2f472ac6fb

View File

@ -16,6 +16,7 @@
#include "nsContentUtils.h"
#include "nsIScriptSecurityManager.h"
#include "nsJSPrincipals.h"
#include "nsIScriptError.h"
#include "jswrapper.h"
extern PRLogModuleInfo *MCD;
@ -106,7 +107,18 @@ nsresult EvaluateAdminConfigScript(const char *js_buffer, size_t length,
nsAutoCString script(js_buffer, length);
JS::RootedValue v(cx);
rv = xpc->EvalInSandboxObject(NS_ConvertUTF8toUTF16(script), filename, cx,
nsString convertedScript = NS_ConvertUTF8toUTF16(script);
if (convertedScript.Length() == 0) {
nsContentUtils::ReportToConsoleNonLocalized(
NS_LITERAL_STRING("Your AutoConfig file is ASCII. Please convert it to UTF-8."),
nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("autoconfig"),
nullptr);
/* If the length is 0, the conversion failed. Fallback to ASCII */
convertedScript = NS_ConvertASCIItoUTF16(script);
}
rv = xpc->EvalInSandboxObject(convertedScript, filename, cx,
autoconfigSb, JSVERSION_LATEST, &v);
NS_ENSURE_SUCCESS(rv, rv);