Bug 1193625 - Fallback to ASCII if AutoConfig UTF-8 conversion fails. r=Mossop, mrbkap, a=sylvestre
authorMike Kaply <mozilla@kaply.com>
Mon, 28 Sep 2015 08:04:47 -0500
changeset 296171 369c340650cc3d0f40f0c78142289c323572db65
parent 296170 87eaa176fb4dda9a22e986b05d9722fa6b61db15
child 296172 ea609f3830eacc917728d3e1994aa481c00d7f2f
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop, mrbkap, sylvestre
bugs1193625
milestone43.0a2
Bug 1193625 - Fallback to ASCII if AutoConfig UTF-8 conversion fails. r=Mossop, mrbkap, a=sylvestre
extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp
--- a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp
+++ b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp
@@ -11,16 +11,17 @@
 #include "nsString.h"
 #include "nsIPrefService.h"
 #include "nspr.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Maybe.h"
 #include "nsContentUtils.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsJSPrincipals.h"
+#include "nsIScriptError.h"
 #include "jswrapper.h"
 
 extern PRLogModuleInfo *MCD;
 using mozilla::AutoSafeJSContext;
 
 //*****************************************************************************
 
 static JS::PersistentRooted<JSObject *> autoconfigSb;
@@ -101,15 +102,26 @@ nsresult EvaluateAdminConfigScript(const
         return rv;
     }
 
     AutoSafeJSContext cx;
     JSAutoCompartment ac(cx, autoconfigSb);
 
     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);
 
     return NS_OK;
 }