Skip to content
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

Update jquery-fix.js for DataTable allowed tags #9746

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mercury64
Copy link

@mercury64 mercury64 commented Mar 19, 2024

DataTable allowed Tag array has html tags that are non-existant.

This updates the datatable tags to what they should be.

Specifically allows dynamically adding rows to a DataTable.

Current broken jquery-fix.js file:

...
	dataTableAllowedTag = [
		"<tbody/>",
		"<tr/>",
		"<td />",
		"<td/>"
	],
...

Proposed fix:

	dataTableAllowedTag = [
		"<tbody>", "<tr>", "<td>", "<td>",
		"</tbody>", "</tr>", "</td>", "</td>"
	],

Related issues / Requêtes associées
#9293
#9610

Original commit that caused this issue:
581e165

DataTable allowed Tag array has html tags that are non-existant.

This updates the datatable tags to what they should be.
Specifically allows dynamically adding rows to a DataTable.
@pearl-nguyen
Copy link

This proposed fix is working for me. Please review. Thanks

@pearl-nguyen
Copy link

pearl-nguyen commented Mar 20, 2024

Can we also update jquery-fix to fix the following case:

$("#tbody").append("<tr><td>a</td><td>a</td><td>a</td><td>a</td><td>a</td></tr>")

Change to dataTableAllowedTag does not help to fix this case.

This proposed solution #9293 (comment) fixes this issue

<script> (function(){ const jQueryOriginalFunctions = { append: jQuery.fn.append, prepend: jQuery.fn.prepend, before: jQuery.fn.before, after: jQuery.fn.after, replaceWith: jQuery.fn.replaceWith, init: jQuery.fn.init, html: jQuery.html }; // Prevent WET-BOEW for overriding these functions without causing a TypeError in the WET-BOEW code Object.defineProperty(jQuery.fn, "append", {get:function(){return jQueryOriginalFunctions.append;}, set:function(){}}); Object.defineProperty(jQuery.fn, "prepend", {get:function(){return jQueryOriginalFunctions.prepend;}, set:function(){}}); Object.defineProperty(jQuery.fn, "before", {get:function(){return jQueryOriginalFunctions.before;}, set:function(){}}); Object.defineProperty(jQuery.fn, "after", {get:function(){return jQueryOriginalFunctions.after;}, set:function(){}}); Object.defineProperty(jQuery.fn, "replaceWith", {get:function(){return jQueryOriginalFunctions.replaceWith;}, set:function(){}}); Object.defineProperty(jQuery, "html", {get:function(){return jQueryOriginalFunctions.html;}, set:function(){}}); })(); </script>

@duboisp
Copy link
Member

duboisp commented Mar 21, 2024

@Garneauma can you review, reproduce the issue and test is change request are fixing it. Thanks

@duboisp duboisp requested a review from Garneauma March 21, 2024 15:57
@Garneauma
Copy link
Contributor

@pearl-nguyen I have just tested your fix and unfortunately it doesn't seem to fix the issue.

Question: what is the intention behind adding that row? Is it simply to add a row to your datatable table? If it is, datatable has a simple way to do so: https://datatables.net/reference/api/row.add()

If that is not the case, could you please explain further what is your intention with that append.

Unfortunately, according to this issue: cure53/DOMPurify#324, it seems that the issue with the append is that the browser does not allow rows to be inserted outside of a table element. It is not DOMPurify itself that does not allow it.

@Garneauma
Copy link
Contributor

@pearl-nguyen Do you have any update on this?

@pearl-nguyen
Copy link

@Garneauma, we are in the process of rewriting our app. Therefore, we do not want to spend resources on fixing existing applications. Recent version of wet broke the javascript in our applications that require changes in many places. The propsed soluton help to fix the issue. thanks

@Garneauma Garneauma added the Need: Test example Describe a test with step by step, code sample, screen capture and the expected results. label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Need: Test example Describe a test with step by step, code sample, screen capture and the expected results.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants