Skip to content

Commit 0ddae51

Browse files
DanCechdeniszh
authored andcommitted
html-encode text passed to Ext.Msg
1 parent 9ab504d commit 0ddae51

1 file changed

Lines changed: 25 additions & 21 deletions

File tree

webapp/content/js/dashboard.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ function hasPermission(permission) {
157157
return false;
158158
}
159159

160+
function htmlEncode(input) {
161+
return input.replace(/[^a-zA-Z0-9 ]/g, function (chr) {
162+
return '&#' + chr.charCodeAt() + ';';
163+
});
164+
}
165+
160166
function initDashboard () {
161167

162168
// Populate naming-scheme based datastructures
@@ -800,7 +806,7 @@ function initDashboard () {
800806
}
801807

802808
if (initialError) {
803-
Ext.Msg.alert('Error', initialError);
809+
Ext.Msg.alert('Error', htmlEncode(initialError));
804810
}
805811
}
806812

@@ -874,7 +880,7 @@ function buildQuery (queryEvent) {
874880
}
875881
}
876882

877-
Ext.Msg.alert('Error', 'Failed to build query, could not find "' + queryEvent.combo.getId() + '" field');
883+
Ext.Msg.alert('Error', htmlEncode('Failed to build query, could not find "' + queryEvent.combo.getId() + '" field'));
878884
queryEvent.cancel = true;
879885
}
880886

@@ -1750,7 +1756,7 @@ function doShare() {
17501756
callback: function (options, success, response) {
17511757
var result = Ext.decode(response.responseText);
17521758
if (result.error) {
1753-
Ext.Msg.alert('Error', 'There was an error saving this dashboard: ' + result.error);
1759+
Ext.Msg.alert('Error', htmlEncode('There was an error saving this dashboard: ' + result.error));
17541760
} else {
17551761
setDashboardName(result.name);
17561762
sendSaveRequest(result.name); // Resave the state with the proper dashboardName now
@@ -2783,7 +2789,7 @@ function sendSaveTemplateRequest(name, key) {
27832789
success: function (response) {
27842790
var result = Ext.decode(response.responseText);
27852791
if (result.error) {
2786-
Ext.Msg.alert('Error', 'There was an error saving this dashboard as a template: ' + result.error);
2792+
Ext.Msg.alert('Error', htmlEncode('There was an error saving this dashboard as a template: ' + result.error));
27872793
}
27882794
},
27892795
failure: failedAjaxCall
@@ -2800,7 +2806,7 @@ function sendSaveRequest(name) {
28002806
success: function (response) {
28012807
var result = Ext.decode(response.responseText);
28022808
if (result.error) {
2803-
Ext.Msg.alert('Error', 'There was an error saving this dashboard: ' + result.error);
2809+
Ext.Msg.alert('Error', htmlEncode('There was an error saving this dashboard: ' + result.error));
28042810
}
28052811
if(newURL) {
28062812
window.location = newURL;
@@ -2818,7 +2824,7 @@ function sendLoadRequest(name) {
28182824
success: function (response) {
28192825
var result = Ext.decode(response.responseText);
28202826
if (result.error) {
2821-
Ext.Msg.alert('Error Loading Dashboard', result.error);
2827+
Ext.Msg.alert('Error Loading Dashboard', htmlEncode(result.error));
28222828
} else {
28232829
applyState(result.state);
28242830
navBar.collapse(false);
@@ -2839,7 +2845,7 @@ function sendLoadTemplateRequest(name, value) {
28392845
success: function (response) {
28402846
var result = Ext.decode(response.responseText);
28412847
if (result.error) {
2842-
Ext.Msg.alert('Error Loading Template', result.error);
2848+
Ext.Msg.alert('Error Loading Template', htmlEncode(result.error));
28432849
} else {
28442850
applyState(result.state);
28452851
navBar.collapse(false);
@@ -2962,9 +2968,9 @@ function deleteDashboard(name) {
29622968
success: function (response) {
29632969
var result = Ext.decode(response.responseText);
29642970
if (result.error) {
2965-
Ext.Msg.alert('Error', 'Failed to delete dashboard \'' + name + '\': ' + result.error);
2971+
Ext.Msg.alert('Error', htmlEncode('Failed to delete dashboard \'' + name + '\': ' + result.error));
29662972
} else {
2967-
Ext.Msg.alert('Dashboard Deleted', 'The ' + name + ' dashboard was deleted successfully.');
2973+
Ext.Msg.alert('Dashboard Deleted', htmlEncode('The ' + name + ' dashboard was deleted successfully.'));
29682974
}
29692975
},
29702976
failure: failedAjaxCall
@@ -2977,9 +2983,9 @@ function deleteTemplate(name) {
29772983
success: function (response) {
29782984
var result = Ext.decode(response.responseText);
29792985
if (result.error) {
2980-
Ext.Msg.alert('Error', 'Failed to delete template \'' + name + '\': ' + result.error);
2986+
Ext.Msg.alert('Error', htmlEncode('Failed to delete template \'' + name + '\': ' + result.error));
29812987
} else {
2982-
Ext.Msg.alert('Template Deleted', 'The ' + name + ' template was deleted successfully.');
2988+
Ext.Msg.alert('Template Deleted', htmlEncode('The ' + name + ' template was deleted successfully.'));
29832989
}
29842990
},
29852991
failure: failedAjaxCall
@@ -3000,7 +3006,7 @@ function setDashboardName(name) {
30003006
var urlparts = location.href.split('#')[0].split('/');
30013007
var i = urlparts.indexOf('dashboard');
30023008
if (i == -1) {
3003-
Ext.Msg.alert('Error', 'urlparts = ' + Ext.encode(urlparts) + ' and indexOf(dashboard) = ' + i);
3009+
Ext.Msg.alert('Error', htmlEncode('urlparts = ' + Ext.encode(urlparts) + ' and indexOf(dashboard) = ' + i));
30043010
return;
30053011
}
30063012
urlparts = urlparts.slice(0, i+1);
@@ -3018,7 +3024,7 @@ function setDashboardName(name) {
30183024
function failedAjaxCall(response, options) {
30193025
Ext.Msg.alert(
30203026
'Ajax Error',
3021-
'Ajax call failed, response was :' + response.responseText
3027+
htmlEncode('Ajax call failed, response was :' + response.responseText)
30223028
);
30233029
}
30243030

@@ -3101,7 +3107,7 @@ function showDashboardFinder() {
31013107
fields: [{
31023108
name: 'name',
31033109
sortType: function(value) {
3104-
// Make sorting case-insensitive
3110+
// Make sorting case-insensitive
31053111
return value.toLowerCase();
31063112
}
31073113
}],
@@ -3133,7 +3139,7 @@ function showDashboardFinder() {
31333139

31343140
Ext.Msg.confirm(
31353141
'Delete Dashboard',
3136-
'Are you sure you want to delete the ' + name + ' dashboard?',
3142+
htmlEncode('Are you sure you want to delete the ' + name + ' dashboard?'),
31373143
function (button) {
31383144
if (button == 'yes') {
31393145
deleteDashboard(name);
@@ -3273,8 +3279,8 @@ function showTemplateFinder() {
32733279
var name = record.data.name;
32743280

32753281
Ext.Msg.confirm(
3276-
'Delete Template',
3277-
'Are you sure you want to delete the ' + name + ' template?',
3282+
'Delete Template',
3283+
htmlEncode('Are you sure you want to delete the ' + name + ' template?'),
32783284
function (button) {
32793285
if (button == 'yes') {
32803286
deleteTemplate(name);
@@ -3622,9 +3628,9 @@ function showLoginForm() {
36223628
failure: function(form, action) {
36233629
if (action.failureType == 'server') {
36243630
var obj = Ext.util.JSON.decode(action.response.responseText);
3625-
Ext.Msg.alert('Login Failed!', obj.errors.reason);
3631+
Ext.Msg.alert('Login Failed!', htmlEncode(obj.errors.reason));
36263632
} else {
3627-
Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText);
3633+
Ext.Msg.alert('Warning!', htmlEncode('Authentication server is unreachable : ' + action.response.responseText));
36283634
}
36293635
login.getForm().reset();
36303636
}
@@ -3661,5 +3667,3 @@ function logout() {
36613667
}
36623668
});
36633669
}
3664-
3665-

0 commit comments

Comments
 (0)