Reviewers: felix8a,

Description:
http://code.google.com/p/google-caja/issues/detail?id=1174

ie[67] doesn't let you change a button's type after it's created.
it's the same as the <input> type problem, you have to specify the
type in createElement.  bridal's cloneNode handles <input> correctly
but not <button.


This change fixes constructClone in bridal.js.  I also checked
html4-attributes-defs.json to see whether there are any other nodes
with a "type" or "value" attribute that need to be fixed up.  The only
other ones are PARAM and LI, UK, OL, and disallowed elements like
OBJECT and LINK, none of which are inputs.

Please review this at http://codereview.appspot.com/165098

Affected files:
  M     src/com/google/caja/plugin/bridal.js


Index: src/com/google/caja/plugin/bridal.js
===================================================================
--- src/com/google/caja/plugin/bridal.js        (revision 3895)
+++ src/com/google/caja/plugin/bridal.js        (working copy)
@@ -90,6 +90,7 @@
   }

   var endsWith__ = /__$/;
+  var escapeAttrib = html.escapeAttrib;
   function constructClone(node, deep) {
     var clone;
     if (node.nodeType === 1 && featureExtendedCreateElement) {
@@ -113,18 +114,22 @@
       // value property.
       switch (node.tagName) {
         case 'INPUT':
-          tagDesc = '<input name="' + html.escapeAttrib(node.name)
-              + '" type="' + html.escapeAttrib(node.type)
-              + '" value="' + html.escapeAttrib(node.defaultValue) + '"'
+          tagDesc = '<input name="' + escapeAttrib(node.name)
+              + '" type="' + escapeAttrib(node.type)
+              + '" value="' + escapeAttrib(node.defaultValue) + '"'
               + (node.defaultChecked ? ' checked="checked">' : '>');
           break;
+        case 'BUTTON':
+          tagDesc = '<button value="' + escapeAttrib(node.defaultValue)
+              + '" type="' + escapeAttrib(node.type) + '">';
+          break;
         case 'OPTION':
           tagDesc = '<option '
               + (node.defaultSelected ? ' selected="selected">' : '>');
           break;
         case 'TEXTAREA':
           tagDesc = '<textarea value="'
-              + html.escapeAttrib(node.defaultValue) + '">';
+              + escapeAttrib(node.defaultValue) + '">';
           break;
       }

@@ -344,7 +349,7 @@
     if (featureExtendedCreateElement) {
       var tag = ['<', tagName];
       for (var i = 0, n = attribs.length; i < n; i += 2) {
- tag.push(' ', attribs[i], '="', html.escapeAttrib(attribs[i + 1]), '"');
+        tag.push(' ', attribs[i], '="', escapeAttrib(attribs[i + 1]), '"');
       }
       tag.push('>');
       return document.createElement(tag.join(''));


Reply via email to