Browse Source

Merge pull request #238 from ice5050/hotfix/DoubleQuoteInRowAttributes

add function escapeHTML for preventing add custom row attribute with dou...
文翼 11 years ago
parent
commit
48aade4572
1 changed files with 13 additions and 1 deletions
  1. 13 1
      src/bootstrap-table.js

+ 13 - 1
src/bootstrap-table.js

@@ -100,6 +100,18 @@
         return defaultValue;
         return defaultValue;
     };
     };
 
 
+    var escapeHTML = function (text) {
+        if (typeof text == 'string') {
+            return text
+                .replace(/&/g, "&")
+                .replace(/</g, "&lt;")
+                .replace(/>/g, "&gt;")
+                .replace(/"/g, "&quot;")
+                .replace(/'/g, "&#039;");
+        }
+        return text;
+    };
+
     // BOOTSTRAP TABLE CLASS DEFINITION
     // BOOTSTRAP TABLE CLASS DEFINITION
     // ======================
     // ======================
 
 
@@ -893,7 +905,7 @@
 
 
             if (attributes) {
             if (attributes) {
                 for (var key in attributes) {
                 for (var key in attributes) {
-                    htmlAttributes.push(sprintf('%s="%s"', key, attributes[key]));
+                    htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
                 }
                 }
             }
             }