Przeglądaj źródła

JSON格式化工具,源码模式增加html tag encode

zxlie 7 lat temu
rodzic
commit
13b5324c2a
2 zmienionych plików z 16 dodań i 2 usunięć
  1. 15 1
      apps/json-format/format-lib.js
  2. 1 1
      apps/manifest.json

+ 15 - 1
apps/json-format/format-lib.js

@@ -84,6 +84,20 @@ let JsonFormatEntrance = (function () {
         }
     };
 
+    /**
+     * HTML特殊字符格式化
+     * @param str
+     * @returns {*}
+     */
+    let htmlspecialchars = function(str){
+        str = str.replace(/&/g, '&');
+        str = str.replace(/</g, '&lt;');
+        str = str.replace(/>/g, '&gt;');
+        str = str.replace(/"/g, '&quot;');
+        str = str.replace(/'/g, '&#039;');
+        return str;
+    };
+
 
     /**
      * 执行代码格式化
@@ -94,7 +108,7 @@ let JsonFormatEntrance = (function () {
         cachedJsonString = JSON.stringify(JSON.parse(jsonStr), null, 4);
 
         _initElements();
-        jfPre.html(cachedJsonString);
+        jfPre.html(htmlspecialchars(cachedJsonString));
 
         JsonFormatDealer.postMessage({
             type: "SENDING TEXT",

+ 1 - 1
apps/manifest.json

@@ -1,6 +1,6 @@
 {
   "name": "WEB前端助手(FeHelper)",
-  "version": "2018.11.0612",
+  "version": "2018.11.1217",
   "manifest_version": 2,
   "default_locale": "zh_CN",
   "description": "FE助手:包括JSON格式化、二维码生成与解码、信息编解码、代码压缩、美化、页面取色、Markdown与HTML互转、网页滚动截屏、正则表达式、时间转换工具、编码规范检测、页面性能检测、Ajax接口调试、密码生成器、JSON比对工具、网页编码设置、便签笔记",