[Pkg-mozext-commits] [firebug] 79/82: issue6140: detect when downloading an HTML file with include()

David Prévot taffit at moszumanska.debian.org
Mon Mar 31 22:45:43 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to tag fbtest-1.11.2
in repository firebug.

commit 88080a69ef94d66ee7396413689841c6edd511ea
Author: Florent FAYOLLE <cold_sun at hotmail.fr>
Date:   Fri Dec 21 19:01:04 2012 +0100

    issue6140: detect when downloading an HTML file with include()
---
 .../content/firebug/console/commandLineInclude.js  | 33 ++++++++++++++++++++--
 extension/locale/en-US/firebug.properties          |  5 ++++
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/extension/content/firebug/console/commandLineInclude.js b/extension/content/firebug/console/commandLineInclude.js
index 59a1960..cffee45 100644
--- a/extension/content/firebug/console/commandLineInclude.js
+++ b/extension/content/firebug/console/commandLineInclude.js
@@ -306,7 +306,7 @@ function CommandLineIncludeObject()
 
 var CommandLineInclude = Obj.extend(Firebug.Module,
 {
-    onSuccess: function(newAlias, context, loadingMsgRow, xhr)
+    onSuccess: function(newAlias, context, loadingMsgRow, xhr, hasWarnings)
     {
         var urlComponent = xhr.channel.URI.QueryInterface(Ci.nsIURL);
         var filename = urlComponent.fileName, url = urlComponent.spec;
@@ -320,7 +320,8 @@ var CommandLineInclude = Obj.extend(Firebug.Module,
             this.log("aliasCreated", [newAlias], [context, "info"]);
         }
 
-        this.log("includeSuccess", [filename], [context, "info", true]);
+        if (!hasWarnings)
+            this.log("includeSuccess", [filename], [context, "info", true]);
     },
 
     onError: function(context, url, loadingMsgRow)
@@ -440,9 +441,19 @@ var CommandLineInclude = Obj.extend(Firebug.Module,
             if (xhr.status !== 200)
                 return errorFunction.apply(this, arguments);
             var codeToEval = xhr.responseText;
+            var hasWarnings = false;
+
+            // test if the content is an HTML file, which is the most current after a mistake
+            if (!isValidJS(codeToEval))
+            {
+                CommandLineInclude.log("invalidSyntax", [], [context, "warn"]);
+                CommandLineInclude.clearLoadingMessage(loadingMsgRow);
+                hasWarnings = true;
+            }
+
             Firebug.CommandLine.evaluateInWebPage(codeToEval, context);
             if (successFunction)
-                successFunction(xhr);
+                successFunction(xhr, hasWarnings);
         }
 
         if (errorFunction)
@@ -543,6 +554,22 @@ IncludeEditor.prototype = domplate(Firebug.InlineEditor.prototype,
     }
 });
 
+function isValidJS(codeToCheck)
+{
+    try
+    {
+        new Function(codeToCheck);
+        return true;
+    }
+    catch(ex)
+    {
+        if (ex instanceof SyntaxError)
+            return false;
+        else
+            throw ex;
+    }
+};
+
 // ********************************************************************************************* //
 // Registration
 
diff --git a/extension/locale/en-US/firebug.properties b/extension/locale/en-US/firebug.properties
index 4fe7d3f..47a6933 100644
--- a/extension/locale/en-US/firebug.properties
+++ b/extension/locale/en-US/firebug.properties
@@ -811,6 +811,11 @@ commandline.include.loadFail=The following script could not be loaded: %S
 # %S = the filename
 commandline.include.invalidRequestProtocol=Only HTTP/HTTPS protocols are supported.
 
+# LOCALIZATION NOTE (commandline.include.invalidSyntax): For the include() function. This message is displayed
+# in the Console panel when the user tries to execute a non-Javascript file 
+# or when the script contains syntax errors
+commandline.include.invalidSyntax=The inclusion failed due to syntax errors. Does the file really contain JavaScript?
+
 # LOCALIZATION NOTE (commandline.include.aliasCreated): For the include() function. This message is displayed
 # in the Console panel when a new alias is created successfully
 # %S = the alias name

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firebug.git



More information about the Pkg-mozext-commits mailing list