Explorar el Código

修复json自动格式化在某极端情况下的bug

Alien hace 10 años
padre
commit
6012f30d4c

+ 1 - 1
chrome/manifest.json

@@ -1,6 +1,6 @@
 {
     "name": "WEB前端助手(FeHelper)",
-    "version": "6.2",
+    "version": "6.3",
     "manifest_version": 2,
 
     "default_locale": "zh_CN",

+ 1 - 1
chrome/online.manifest.json

@@ -1,6 +1,6 @@
 {
     "name": "WEB前端助手(FeHelper)",
-    "version": "6.2",
+    "version": "6.3",
     "manifest_version": 2,
 
     "default_locale": "zh_CN",

+ 8 - 3
chrome/static/js/jsonformat/contentscript-jsonformat.js

@@ -82,6 +82,7 @@ baidu.csJsonFormat = (function () {
         var funcName = null;
         // json对象
         var jsonObj = null;
+        var newSource = '';
 
         // 下面校验给定字符串是否为一个合法的json
         try {
@@ -90,7 +91,7 @@ baidu.csJsonFormat = (function () {
             var matches = reg.exec(source);
             if (matches != null) {
                 funcName = matches[1];
-                var newSource = matches[2];
+                newSource = matches[2];
                 jsonObj = new Function("return " + newSource)();
             }
         } catch (ex) {
@@ -115,7 +116,11 @@ baidu.csJsonFormat = (function () {
         if (jsonObj != null && typeof jsonObj == "object") {
             try {
                 // 要尽量保证格式化的东西一定是一个json,所以需要把内容进行JSON.stringify处理
-                source = JSON.stringify(jsonObj);
+                newSource = JSON.stringify(jsonObj);
+                // 如果newSource的长度比原source长度短很多的话,猜测应该是格式化错了,需要撤销操作
+                if(newSource.length * 2 < source.length) {
+                    return ;
+                }
             } catch (ex) {
                 // 通过JSON反解不出来的,一定有问题
                 return;
@@ -141,7 +146,7 @@ baidu.csJsonFormat = (function () {
             });
 
             JsonFormatEntrance.clear();
-            JsonFormatEntrance.format(source);
+            JsonFormatEntrance.format(newSource);
 
             // 如果是JSONP格式的,需要把方法名也显示出来
             if (funcName != null) {

+ 4 - 0
chrome/static/js/jsonformat/json-format-ent.js

@@ -107,6 +107,10 @@ var JsonFormatEntrance = (function () {
                 }, false);
 
                 buttonCollapseAll.addEventListener('click', function () {
+                    // 如果内容还没有格式化过,需要再格式化一下
+                    if(plainOn) {
+                        buttonFormatted.click();
+                    }
                     // When collapaseAll button clicked...
                     if (!plainOn) {
                         if(buttonCollapseAll.innerText == '折叠所有'){

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
chrome/template/fehelper_regexp.html


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio