Skip to content

Commit

Permalink
d2ee4b9bdcce1d96b9f9dfd8a1a6fcb5e4616466 Fix: Improve HTML stripping …
Browse files Browse the repository at this point in the history
…regular expressions

Fix: Use `DataTable.stripHtml()` to allow an external parser to be used

8cbe11b44ca3b6f722d836f3949d0da6e3a28a93 Merge branch 'master' of github.com:DataTables/Buttons

Sync to source repo @8cbe11b44ca3b6f722d836f3949d0da6e3a28a93
  • Loading branch information
dtbuild committed Apr 10, 2024
1 parent 0a3cc49 commit 0f2a52f
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
],
"src-repo": "http://github.com/DataTables/Buttons",
"last-tag": "3.0.1",
"last-sync": "be5df003b0760bc55d98b96575a78b253c904f4d"
"last-sync": "8cbe11b44ca3b6f722d836f3949d0da6e3a28a93"
}
9 changes: 5 additions & 4 deletions js/buttons.colVis.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ $.extend(DataTable.ext.buttons, {
title = title
.replace(/\n/g, ' ') // remove new lines
.replace(/<br\s*\/?>/gi, ' ') // replace line breaks with spaces
.replace(/<select(.*?)<\/select>/g, '') // remove select tags, including options text
.replace(/<!\-\-.*?\-\->/g, '') // strip HTML comments
.replace(/<.*?>/g, '') // strip HTML
.replace(/^\s+|\s+$/g, ''); // trim
.replace(/<select(.*?)<\/select\s*>/g, '') // remove select tags, including options text
.replace(/<!\-\-.*?\-\-!?>/g, ''); // strip HTML comments

// Use whatever HTML stripper DataTables is configured for
title = DataTable.stripHtml(title).trim();

return conf.columnText ? conf.columnText(dt, idx, title) : title;
}
Expand Down
2 changes: 1 addition & 1 deletion js/buttons.colVis.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/buttons.colVis.min.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* Column visibility buttons for Buttons and DataTables.
* © SpryMedia Ltd - datatables.net/license
*/
import jQuery from"jquery";import DataTable from"datatables.net";import Buttons from"datatables.net-buttons";let $=jQuery;$.extend(DataTable.ext.buttons,{colvis:function(n,t){var i=null,o={extend:"collection",init:function(n,t){i=t},text:function(n){return n.i18n("buttons.colvis","Column visibility")},className:"buttons-colvis",closeButton:!1,buttons:[{extend:"columnsToggle",columns:t.columns,columnText:t.columnText}]};return n.on("column-reorder.dt"+t.namespace,function(){n.button(null,n.button(null,i).node()).collectionRebuild([{extend:"columnsToggle",columns:t.columns,columnText:t.columnText}])}),o},columnsToggle:function(n,t){return n.columns(t.columns).indexes().map(function(n){return{extend:"columnToggle",columns:n,columnText:t.columnText}}).toArray()},columnToggle:function(n,t){return{extend:"columnVisibility",columns:t.columns,columnText:t.columnText}},columnsVisibility:function(n,t){return n.columns(t.columns).indexes().map(function(n){return{extend:"columnVisibility",columns:n,visibility:t.visibility,columnText:t.columnText}}).toArray()},columnVisibility:{columns:void 0,text:function(n,t,i){return i._columnText(n,i)},className:"buttons-columnVisibility",action:function(n,t,i,o){var t=t.columns(o.columns),e=t.visible();t.visible(void 0!==o.visibility?o.visibility:!(e.length&&e[0]))},init:function(i,n,o){var e=this;n.attr("data-cv-idx",o.columns),i.on("column-visibility.dt"+o.namespace,function(n,t){t.bDestroying||t.nTable!=i.settings()[0].nTable||e.active(i.column(o.columns).visible())}).on("column-reorder.dt"+o.namespace,function(){o.destroying||1===i.columns(o.columns).count()&&(e.text(o._columnText(i,o)),e.active(i.column(o.columns).visible()))}),this.active(i.column(o.columns).visible())},destroy:function(n,t,i){n.off("column-visibility.dt"+i.namespace).off("column-reorder.dt"+i.namespace)},_columnText:function(n,t){var i,o;return"string"==typeof t.text?t.text:(i=n.column(t.columns).index(),o=(o=(o=n.settings()[0].aoColumns[i].sTitle)||n.column(i).header().innerHTML).replace(/\n/g," ").replace(/<br\s*\/?>/gi," ").replace(/<select(.*?)<\/select>/g,"").replace(/<!\-\-.*?\-\->/g,"").replace(/<.*?>/g,"").replace(/^\s+|\s+$/g,""),t.columnText?t.columnText(n,i,o):o)}},colvisRestore:{className:"buttons-colvisRestore",text:function(n){return n.i18n("buttons.colvisRestore","Restore visibility")},init:function(n,t,i){n.columns().every(function(){var n=this.init();void 0===n.__visOriginal&&(n.__visOriginal=this.visible())})},action:function(n,t,i,o){t.columns().every(function(n){var t=this.init();this.visible(t.__visOriginal)})}},colvisGroup:{className:"buttons-colvisGroup",action:function(n,t,i,o){t.columns(o.show).visible(!0,!1),t.columns(o.hide).visible(!1,!1),t.columns.adjust()},show:[],hide:[]}});export default DataTable;
import jQuery from"jquery";import DataTable from"datatables.net";import Buttons from"datatables.net-buttons";let $=jQuery;$.extend(DataTable.ext.buttons,{colvis:function(n,t){var i=null,o={extend:"collection",init:function(n,t){i=t},text:function(n){return n.i18n("buttons.colvis","Column visibility")},className:"buttons-colvis",closeButton:!1,buttons:[{extend:"columnsToggle",columns:t.columns,columnText:t.columnText}]};return n.on("column-reorder.dt"+t.namespace,function(){n.button(null,n.button(null,i).node()).collectionRebuild([{extend:"columnsToggle",columns:t.columns,columnText:t.columnText}])}),o},columnsToggle:function(n,t){return n.columns(t.columns).indexes().map(function(n){return{extend:"columnToggle",columns:n,columnText:t.columnText}}).toArray()},columnToggle:function(n,t){return{extend:"columnVisibility",columns:t.columns,columnText:t.columnText}},columnsVisibility:function(n,t){return n.columns(t.columns).indexes().map(function(n){return{extend:"columnVisibility",columns:n,visibility:t.visibility,columnText:t.columnText}}).toArray()},columnVisibility:{columns:void 0,text:function(n,t,i){return i._columnText(n,i)},className:"buttons-columnVisibility",action:function(n,t,i,o){var t=t.columns(o.columns),e=t.visible();t.visible(void 0!==o.visibility?o.visibility:!(e.length&&e[0]))},init:function(i,n,o){var e=this;n.attr("data-cv-idx",o.columns),i.on("column-visibility.dt"+o.namespace,function(n,t){t.bDestroying||t.nTable!=i.settings()[0].nTable||e.active(i.column(o.columns).visible())}).on("column-reorder.dt"+o.namespace,function(){o.destroying||1===i.columns(o.columns).count()&&(e.text(o._columnText(i,o)),e.active(i.column(o.columns).visible()))}),this.active(i.column(o.columns).visible())},destroy:function(n,t,i){n.off("column-visibility.dt"+i.namespace).off("column-reorder.dt"+i.namespace)},_columnText:function(n,t){var i,o;return"string"==typeof t.text?t.text:(i=n.column(t.columns).index(),o=(o=(o=n.settings()[0].aoColumns[i].sTitle)||n.column(i).header().innerHTML).replace(/\n/g," ").replace(/<br\s*\/?>/gi," ").replace(/<select(.*?)<\/select\s*>/g,"").replace(/<!\-\-.*?\-\-!?>/g,""),o=DataTable.stripHtml(o).trim(),t.columnText?t.columnText(n,i,o):o)}},colvisRestore:{className:"buttons-colvisRestore",text:function(n){return n.i18n("buttons.colvisRestore","Restore visibility")},init:function(n,t,i){n.columns().every(function(){var n=this.init();void 0===n.__visOriginal&&(n.__visOriginal=this.visible())})},action:function(n,t,i,o){t.columns().every(function(n){var t=this.init();this.visible(t.__visOriginal)})}},colvisGroup:{className:"buttons-colvisGroup",action:function(n,t,i,o){t.columns(o.show).visible(!0,!1),t.columns(o.hide).visible(!1,!1),t.columns.adjust()},show:[],hide:[]}});export default DataTable;
9 changes: 5 additions & 4 deletions js/buttons.colVis.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ $.extend(DataTable.ext.buttons, {
title = title
.replace(/\n/g, ' ') // remove new lines
.replace(/<br\s*\/?>/gi, ' ') // replace line breaks with spaces
.replace(/<select(.*?)<\/select>/g, '') // remove select tags, including options text
.replace(/<!\-\-.*?\-\->/g, '') // strip HTML comments
.replace(/<.*?>/g, '') // strip HTML
.replace(/^\s+|\s+$/g, ''); // trim
.replace(/<select(.*?)<\/select\s*>/g, '') // remove select tags, including options text
.replace(/<!\-\-.*?\-\-!?>/g, ''); // strip HTML comments

// Use whatever HTML stripper DataTables is configured for
title = DataTable.stripHtml(title).trim();

return conf.columnText ? conf.columnText(dt, idx, title) : title;
}
Expand Down
10 changes: 5 additions & 5 deletions js/dataTables.buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -1880,15 +1880,15 @@ Buttons.stripData = function (str, config) {

// Always remove script tags
str = str.replace(
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script\s*>/gi,
''
);

// Always remove comments
str = str.replace(/<!\-\-.*?\-\->/g, '');
str = str.replace(/<!\-\-.*?\-\-!?>/g, '');

if (!config || config.stripHtml) {
str = str.replace(/<[^>]*>/g, '');
str = DataTable.stripHtml(str);
}

if (!config || config.trim) {
Expand Down Expand Up @@ -2519,7 +2519,7 @@ var _filename = function (config, dt) {
}

if (filename.indexOf('*') !== -1) {
filename = filename.replace('*', $('head > title').text()).trim();
filename = filename.replace(/\*/g, $('head > title').text()).trim();
}

// Strip characters which the OS will object to
Expand Down Expand Up @@ -2560,7 +2560,7 @@ var _title = function (config, dt) {
return title === null
? null
: title.indexOf('*') !== -1
? title.replace('*', $('head > title').text() || 'Exported data')
? title.replace(/\*/g, $('head > title').text() || 'Exported data')
: title;
};

Expand Down
2 changes: 1 addition & 1 deletion js/dataTables.buttons.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dataTables.buttons.min.mjs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions js/dataTables.buttons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,15 +1840,15 @@ Buttons.stripData = function (str, config) {

// Always remove script tags
str = str.replace(
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script\s*>/gi,
''
);

// Always remove comments
str = str.replace(/<!\-\-.*?\-\->/g, '');
str = str.replace(/<!\-\-.*?\-\-!?>/g, '');

if (!config || config.stripHtml) {
str = str.replace(/<[^>]*>/g, '');
str = DataTable.stripHtml(str);
}

if (!config || config.trim) {
Expand Down Expand Up @@ -2479,7 +2479,7 @@ var _filename = function (config, dt) {
}

if (filename.indexOf('*') !== -1) {
filename = filename.replace('*', $('head > title').text()).trim();
filename = filename.replace(/\*/g, $('head > title').text()).trim();
}

// Strip characters which the OS will object to
Expand Down Expand Up @@ -2520,7 +2520,7 @@ var _title = function (config, dt) {
return title === null
? null
: title.indexOf('*') !== -1
? title.replace('*', $('head > title').text() || 'Exported data')
? title.replace(/\*/g, $('head > title').text() || 'Exported data')
: title;
};

Expand Down

0 comments on commit 0f2a52f

Please sign in to comment.