WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 richedit getXHTML bug, andot, October 25, 2002
     Re:richedit getXHTML bug, Erik Arvidsson, October 25, 2002
         Re:richedit getXHTML bug, andot, October 26, 2002
             Re:richedit getXHTML bug, Erik Arvidsson, October 27, 2002
                 Re:richedit getXHTML bug , andot, October 28, 2002
                     Re:richedit getXHTML bug , Erik Arvidsson, October 28, 2002
                 Re:richedit getXHTML bug, andot, October 28, 2002
             Re:richedit getXHTML bug, Erik Arvidsson, October 27, 2002
                 Re:richedit getXHTML bug, andot, October 28, 2002

Subject: Re:richedit getXHTML bug From: andot Date: October 26, 2002

Yes, I didn't think repliacing '>' with ">" is incorrect, too.

But I notice that some Attributes can include JavaScript or VBScript or any other script languages, if repliacing '>','<','&','"' with "&gt;", "&lt;","&amp;","&quot;", the script will run incorrectly.

 I find most(maybe every) Attributes begin with "on" are event attributes, it means that it must have some script language programs. so if we
use function _fixAttribute() on it, we will get a wrong script language program, and the XHTML we get also work badly.

Of course, there are many other Attributes can include JavaScript, just like 'href' attribute. if we use _fixAttribute() on it, we maybe also get a error script, so now I think the function _fixAttribute() is needless. And I find the following code also can run correctly without the function _fixAttribute().

          if (attrs[i].nodeName != "style") {
            sb.append(" " + (attrs[i].expando ? attrs[i].nodeName : attrs[i].nodeName.toLowerCase()) +
              "=\"" + attrs[i].nodeValue + "\"");
          }
          else sb.append(" style=\"" + node.style.cssText.toLowerCase() + "\"");

And I fix another bug in IE 5/ 5.5 , the decription of this bug in 
http://webfx.eae.net/webboard/index.cgi?action=preview&group=data/group3&id=321,
but I found not only the "
border" attribute has this bug, most (maybe every) attributes with a integer value have this bug, for example, the "width", "height" attributes also have this bug. so I add two function to fix this bug.

function isInt(s){
  return (parseInt(s).toString() == s.toString());
}
function _getAttributeValue(node, i){
  var attrs = node.attributes;
  var result = attrs[i].nodeValue;
  if (isInt(result)) {
    try {
      result = eval("node." + attrs[i].nodeName);
    }
    catch(execption) {}
  }
  return result;
}

and then, modify the function _appendNodeXHTML,

          if (attrs[i].nodeName != "style") {
            sb.append(" " + (attrs[i].expando ? attrs[i].nodeName : attrs[i].nodeName.toLowerCase()) +
              "=\"" + _getAttributeValue(node, i) + "\"");
          }
          else sb.append(" style=\"" + node.style.cssText.toLowerCase() + "\"");

andot
2002-10-26

From: Erik Arvidsson
Sent: October 25, 2002
Subject: Re:richedit getXHTML bug

You are correct that '>' does not need to be replaced in character data. However there is nothing special with attributes starting with "on" in XML. Your code will generate XML that is not well formed and the result will not parse.

Notice that replacing '>' with "&gt;" is correct (but not necessary).

If you are having problem with "&gt;" in your attributes you are not using a compliant XML parser/engine. If this is the case you are better of changing the fixAttribute function.

function _fixAttribute(s) {
return String(s).replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/\"/g, "&quot;");
}

function _fixText(s) {
return String(s).replace(/\&/g, "&amp;").replace(/</g, "&lt;");
}

erik

-------------------------------------------------------

when I use event Attribute in the HTML tags, just like
<button onclick="if (something>0) alert('wrong!');">ok</button>
, the getXHTML method always fix the ">" into "&gt;", but it fix wrong. I think the event Attribute needn't to fix, so I modify the function _appendNodeXHTML(node, sb) in js/getxhtml.js. the following is modified part,
for (var i = 0; i < l; i++) {
if (attrs[i].specified) {
if (attrs[i].nodeName != "style") {
sb.append(" " + (attrs[i].expando ? attrs[i].nodeName : attrs[i].nodeName.toLowerCase()) +
"=\"" + ((attrs[i].nodeName.substring(0, 2) == "on") ? attrs[i].nodeValue : _fixAttribute(attrs[i].nodeValue)) + "\"");
}
else sb.append(" style=\"" + _fixAttribute(node.style.cssText).toLowerCase() + "\"");
}
}





Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX