Results 1 to 5 of 5

Thread: [2.x][DUP] Tree Nodes and Html Special Chars

  1. #1
    Ext User
    Join Date
    Dec 2007
    Posts
    3
    Vote Rating
    0
      0  

    Thumbs up [2.x][DUP] Tree Nodes and Html Special Chars

    Hello,

    I get a bug using string as id for my nodes id in a tree.
    (I use the complete path of a node : it's provided by a webservice and i have no other way to get an integer id).

    The problem appear when the id contain special html chars (such as /test/foo<ss/bar).
    In fact, node id is written as an ext:tree-node-id attribute in dom, but browser decode this value. So in my example I will get : ext:tree-node-id="/test/foo<ss/bar".
    Consequently when I mouse over/out/click, the getNode function (which use this attribute to transform real dom node to treeNode is completly lost : it search a node with the id "/test/foo<ss/bar" instead of the node with the id "/test/foo&lt;ss/bar".

    So for my usage i overwrite the Ext.tree.TreeNodeUI.prototype.renderElements function by transforming the buf variable to use encoded id (Ext.util.Format.htmlEncode(n.id) )
    Code:
    var buf = ['<li class="x-tree-node"><div ext:tree-node-id="',Ext.util.Format.htmlEncode(n.id),'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',
                '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
                '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
                '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
                cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
                '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',
                 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
                '<ul class="x-tree-node-ct" style="display:none;"></ul>',
                "</li>"].join('');
    Note that it isn't tested yet for all browsers but it seems to fix the bug.


    What should be a cool feature too, should be to have an additional parameter in tree to say that text has to be htmlEncoded at render time (ie in this renderElements function :
    Code:
            var text = n.text;
            if(n.getOwnerTree().encodeText){
                text = Ext.util.Format.htmlEncode(text);
            }
    ).
    Last edited by r3gis; 18 Feb 2009 at 12:57 AM. Reason: Duplicate bug

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,222
    Vote Rating
    1010
      0  

    Default

    I don't really think this is a bug, it seems to be a fairly rare case, the node id should ideally be something that can be used for a DOM node.

    I like the idea about encodeText though.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    132
      0  

    Default

    Note: This is a partial duplicate of this post.

    @evant: The node id is used for the "ext:tree-node-id" attribute and not for the "id" attribute, so it is not restricted to valid ID characters and can contain any valid CDATA character.
    The docs should either mention the character restriction for node ids ( no ", < and > ) or it should escape the node id.

  4. #4
    Ext User
    Join Date
    Dec 2007
    Posts
    3
    Vote Rating
    0
      0  

    Default

    I don't really think this is a bug, it seems to be a fairly rare case, the node id should ideally be something that can be used for a DOM node.
    I considered this as a bug since there is cases in which, real node id could be different than id written in dom.
    Even if I agree it's a rare case, doc say that node id it is a string, so it could contain special chars.
    Note that what i described also occure in other cases (since browser try to interpret special chars : (expl, in firefox : "at&lt" will be decoded).


    (P.S. : My premium account isn't activate yet but i work in a company with extjs licenses)

  5. #5
    Ext User
    Join Date
    Dec 2007
    Posts
    3
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by Condor View Post
    Note: This is a partial duplicate of this post.

    @evant: The node id is used for the "ext:tree-node-id" attribute and not for the "id" attribute, so it is not restricted to valid ID characters and can contain any valid CDATA character.
    The docs should either mention the character restriction for node ids ( no ", < and > ) or it should escape the node id.
    Oups, sorry for duplicate (i searched in the forum but probably with bad keywords).

    Ok to add a warning about valid ID in docs.
    For me it will fix the problem, even if it would be better if extjs support special chars in ids (in my case, a webfile, id are path of file/folders and I have to manage all files/folders names)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •