Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to prevent using HTML in tree nodes? #583

Closed
DumboJet opened this issue Apr 7, 2016 · 2 comments
Closed

How to prevent using HTML in tree nodes? #583

DumboJet opened this issue Apr 7, 2016 · 2 comments

Comments

@DumboJet
Copy link

DumboJet commented Apr 7, 2016

I am concerned with security a lot and I have noticed that the node title is rendered as HTML.
Can I prevent that and render the title as text?

Can someone suggest how to best achieve this (preferably without pre-encoding the titles on the server, but doing it on the client)?

I use the tree like so:

        $("#tree").fancytree({
            checkbox: true,
            source: @Html.Raw(@Model.TreeData),
            lazyLoad: function(event, data) {
                data.result =
                $.ajax({
                    url: '/Api/GetFancyTreeContent',
                    type: 'post',
                    data: {
                        catId: data.node.key,
                        skipCache: false
                    }
                });
            },
       ......................

Any input would be appreciated. :)
Thanks. :)

@DumboJet
Copy link
Author

DumboJet commented Apr 7, 2016

OK. This addition seems to be working:

            ...
            createNode: function(e, data) {
                var n = data.node;
                n.plainTitle = n.title; // Keep this for later use...
                n.setTitle($('<div/>').text(n.title).html());
            }
            ...

State any objections you may have. :)

@mar10
Copy link
Owner

mar10 commented Apr 8, 2016

This should work (of course only, if the title is not re-rendered, so you could move this code to the render event).
This topic was brought up before, so I will reconsider a general solution.
See #171

@mar10 mar10 closed this as completed Apr 8, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants