-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML tag in JSON not work #47
Comments
I try to use & lt ; instead < in JSON |
I'm not sure what the issue is exactly. Dynatable works fine with HTML inside the JSON dataset. See this example on JSFiddle. |
Also, I should state too that it's intentional that dynatable does work by default with HTML tags in the JSON. It's been brought up by @akgood that it could be a security concern that dynatable treats HTML within JSON as a trusted entity by default. And he's absolutely right. The reason it doesn't escape HTML entities by default is for the default use-case that you have an HTML table with data and the JSON is being built from that. As in the first example in the docs, the table is populated with little flag images for each country. If the default was to treat JSON as text such that HTML tags get escaped, then you would have your table filled with little icons, you'd call .dynatable() on it, and suddenly when you sort, it'd be filled with escaped html entities and your icons would be gone. One of my requirements for the plugin was to be super simple to implement and to leave your data alone (i.e. making no assumptions on your behalf) by default. I think it's one of those situations where there's not necessarily a right answer. But you can easily configure dynatable to treat JSON data as untrusted if you have, for example, some JSON where an attribute's value has some HTML, which you want that to be treated as plain text and not get inserted into the DOM as HTML (which could expose an XSS vulnerability). In that case, do this if you want it to show escaped html entities: $.dynatableSetup({
writers: {
_attributeWriter: function(record) {
return $('<div />').text(record[this.id]).html();
}
}
}); Or do this if you want it to show the text equivalent (ignoring html entities, images, etc.): $.dynatableSetup({
writers: {
_attributeWriter: function(record) {
return $('<div />').html(record[this.id]).text();
}
}
}); |
I use php to generate pre-json tag
and then include by server side include to table.php according to my post but i can solve by use & lt; and & gt; instead < and > |
I put HTML tag in JSON
such as <a> , <img>
dynatable does not show link or image in row of table
The text was updated successfully, but these errors were encountered: