Skip to content

Commit

Permalink
Replaced usages of jQuery .html() with .text() where HTML wasn't needed.
Browse files Browse the repository at this point in the history
This resolves issue #137.
Remove escaping function, since it is no longer required.
Remove verbose logging
  • Loading branch information
Keilaron authored and netwolfuk committed Jun 30, 2019
1 parent 2675215 commit eccd243
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ WebHookRestApiHealthStatus = {

showDialog: function (title, action, filePath) {
$j("#fixPluginForm input[id='FixPluginaction']").val(action);
$j("#fixPluginDialog .dialogTitle").html(title);
$j("#fixPluginDialog .dialogTitle").text(title);
this.cleanFields(filePath);
this.cleanErrors();
this.showCentered();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
locator = '';
}
jQueryWebhook("#currentTemplateBuildId").empty().append(jQueryWebhook('<option></option>').val(null).html("Loading build history..."))
jQueryWebhook("#currentTemplateBuildId").empty().append(jQueryWebhook('<option></option>').val(null).text("Loading build history..."))
jQueryWebhook.ajax ({
url: window['base_uri'] + '/app/rest/builds?locator=' + locator
+ "state:finished&fields=build(id,number,status,finishDate,buildType(id,name))",
Expand All @@ -185,24 +185,21 @@
'Accept' : 'application/json'
},
success: function (response) {
var myselect = jQueryWebhook('<select>');
myselect.append( jQueryWebhook('<option></option>').val(null).html("Choose a Build...") );
var myselect = jQueryWebhook('#currentTemplateBuildId');
myselect.empty().append( jQueryWebhook('<option></option>').val(null).text("Choose a Build...") );
jQueryWebhook(response.build).each(function(index, build) {
console.log(build);
var desc = build.buildType.name
+ "#" + build.number
+ " - " + build.status + " ("
+ moment(build.finishDate, moment.ISO_8601).fromNow()
+ ")";
console.log(desc);
myselect.append( jQueryWebhook('<option></option>').val(build.id).html(desc) );
myselect.append( jQueryWebhook('<option></option>').val(build.id).text(desc) );
});
jQueryWebhook("#currentTemplateBuildId").empty().append(myselect.html());
},
error: function (response) {
if (response.status == 404) {
jQueryWebhook("#currentTemplateBuildId").empty().append(
jQueryWebhook('<option></option>').val(null).html("No builds found. Choose a different project")
jQueryWebhook('<option></option>').val(null).text("No builds found. Choose a different project.")
);
} else {
console.log(response);
Expand Down Expand Up @@ -245,15 +242,15 @@
function updateSelectedBuildTypes(){
var subText = "";
if(jQueryWebhook('#buildTypeSubProjects').is(':checked')){
subText = " &amp; sub-projects";
subText = " & sub-projects";
}
if(jQueryWebhook('#webHookFormContents input.buildType_single:checked').length == jQueryWebhook('#webHookFormContents input.buildType_single').length){
jQueryWebhook('input.buildType_all').prop('checked', true);
jQueryWebhook('span#selectedBuildCount').html("all" + subText);
jQueryWebhook('span#selectedBuildCount').text("all" + subText);
} else {
jQueryWebhook('input.buildType_all').prop('checked', false);
jQueryWebhook('span#selectedBuildCount').html(jQueryWebhook('#webHookFormContents input.buildType_single:checked').length + subText);
jQueryWebhook('span#selectedBuildCount').text(jQueryWebhook('#webHookFormContents input.buildType_single:checked').length + subText);
}
}
Expand Down Expand Up @@ -383,12 +380,18 @@
jQueryWebhook('#webHookFormContents select#payloadFormatHolder').val(webhook.payloadTemplate + "_" + webhook.payloadFormat).change();
jQueryWebhook('#buildTypeSubProjects').prop('checked', webhook.subProjectsEnabled);
jQueryWebhook.each(webhook.builds, function(){
if (this.enabled){
jQueryWebhook('#buildList').append('<p style="border-bottom:solid 1px #cccccc; margin:0; padding:0.5em;"><label><input checked onclick="updateSelectedBuildTypes();" type=checkbox style="padding-right: 1em;" name="buildTypeId" value="' + this.buildTypeId + '"class="buildType_single">' + this.buildTypeName + '</label></p>');
} else {
jQueryWebhook('#buildList').append('<p style="border-bottom:solid 1px #cccccc; margin:0; padding:0.5em;"><label><input onclick="updateSelectedBuildTypes();" type=checkbox style="padding-right: 1em;" name="buildTypeId" value="' + this.buildTypeId + '"class="buildType_single">' + this.buildTypeName + '</label></p>');
}
jQueryWebhook.each(webhook.builds, function() {
var isChecked = '';
if (this.enabled) {
isChecked = ' checked';
}
var cbox = $j('<input' + isChecked + ' onclick="updateSelectedBuildTypes();" type=checkbox style="padding-right: 1em;" name="buildTypeId" value="' + this.buildTypeId + '"class="buildType_single">');
var label = $j('<label></label>');
label.text(this.buildTypeName);
label.prepend(cbox);
var container = $j('<p style="border-bottom:solid 1px #cccccc; margin:0; padding:0.5em;"></p>');
container.append(label);
$j('#buildList').append(container);
});
populateWebHookAuthExtrasPane(webhook);
Expand Down Expand Up @@ -423,15 +426,6 @@
return name;
}
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
function addWebHooksFromJsonCallback(){
var webhookItems = ProjectBuilds.templatesAndWebhooks.projectWebhookConfig.webHookList;
jQueryWebhook.each(webhookItems, function(webHookKey, webhook){
Expand All @@ -442,14 +436,14 @@
.removeClass('webHookRowTemplate')
.addClass('webHookRow')
.appendTo('#webHookTable > tbody');
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemUrl").html(htmlEscape(webhook.url)).click(function(){BS.EditWebHookDialog.showDialog(webhook.uniqueKey, '#hookPane');});
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemUrl").text(webhook.url).click(function(){BS.EditWebHookDialog.showDialog(webhook.uniqueKey, '#hookPane');});
if (webhook.payloadTemplate === 'none') {
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemFormat").html(webhook.payloadFormatForWeb);
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemFormat").text(webhook.payloadFormatForWeb);
} else {
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemFormat").html("<a href='template.html?template=" + webhook.payloadTemplate +"'>" + webhook.payloadFormatForWeb + "</a>");
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemFormat").html("").append($j("<a href='template.html?template=" + webhook.payloadTemplate +"'></a>").text(webhook.payloadFormatForWeb));
}
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemEvents").html(webhook.enabledEventsListForWeb).click(function(){BS.EditWebHookDialog.showDialog(webhook.uniqueKey,'#hookPane');});
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemBuilds").html(webhook.enabledBuildsListForWeb).click(function(){BS.EditWebHookDialog.showDialog(webhook.uniqueKey, '#buildPane');});
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemEvents").text(webhook.enabledEventsListForWeb).click(function(){BS.EditWebHookDialog.showDialog(webhook.uniqueKey,'#hookPane');});
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemBuilds").text(webhook.enabledBuildsListForWeb).click(function(){BS.EditWebHookDialog.showDialog(webhook.uniqueKey, '#buildPane');});
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemEdit > a").click(function(){BS.EditWebHookDialog.showDialog(webhook.uniqueKey,'#hookPane');});
jQueryWebhook("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemDelete > a").click(function(){BS.WebHookForm.removeWebHook(webhook.uniqueKey,'#hookPane');});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ WebHooksPlugin = {

showDialog: function (title, action, data) {
$j("input[id='WebhookTemplateaction']").val(action);
$j(".dialogTitle").html(title);
$j(".dialogTitle").text(title);
$j("#addTemplateForm #addTemplateDialogSubmit").hide();
$j("#addTemplateForm #addTemplateDialogExpand").show();
$j("#addTemplateForm .templateDetails").hide();
Expand Down Expand Up @@ -77,8 +77,6 @@ WebHooksPlugin = {
this.cleanErrors();

var dialog = this;
//console.log($j("input[id='WebhookTemplateaction']").val());

var myJsonContent = {
id : $j("#addTemplateForm input[id='template.id']").val(),
description : $j("#addTemplateForm input[id='template.description']").val(),
Expand All @@ -87,8 +85,6 @@ WebHooksPlugin = {
format : "jsonTemplate",
};

console.log(myJsonContent);

$j.ajax ({
url: window['base_uri'] + '/app/rest/webhooks/templates',
type: "POST",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ WebHooksPlugin = {
showDialog: function (title, action, id) {
$j("#editWebHookForm input[id='webHookId']").val("none"); // Unset the edit id, so that it doesn't get animated by delete.
$j("input[id='webHookaction']").val(action);
$j(".dialogTitle").html(title);
$j(".dialogTitle").text(title);
this.cleanFields(id);
this.cleanErrors();
this.showCentered();
Expand Down Expand Up @@ -139,7 +139,7 @@ WebHooksPlugin = {
showDialog: function (title, action, id, tab) {

this.formElement().submitAction.value = action;
$j(".dialogTitle").html(title);
$j(".dialogTitle").text(title);
this.cleanFields(id);
this.cleanErrors();

Expand Down Expand Up @@ -221,7 +221,6 @@ WebHooksPlugin = {
var webHookId = "unknown";
$j(responseXML).find("webhook").each(function(error, webhook){
$j("#editWebHookForm input[id='webHookId']").val(webhook.id);
console.log(webhook.id);
});
$j('li.tab').removeAttr('style');
$j("#viewRow_" + $j("#editWebHookForm input[id='webHookId']").val()).animate({
Expand Down Expand Up @@ -290,15 +289,14 @@ WebHooksPlugin = {
var ul = $j('<ul>');

if (response.error) {
ul.append($j('<li/>').html("Error: " + htmlEscape(response.error.message) + " (" + response.error.errorCode + ")"));
ul.append($j('<li/>').text("Error: " + response.error.message + " (" + response.error.errorCode + ")"));
} else {
ul.append($j('<li/>').html("Success: " + htmlEscape(response.statusReason) + " (" + response.statusCode + ")"));
ul.append($j('<li/>').text("Success: " + response.statusReason + " (" + response.statusCode + ")"));
}
ul.append($j('<li/>').html("URL: " + htmlEscape(response.url)));
ul.append($j('<li/>').html("Duration: " + response.executionTime + " @ " + moment(response.dateTime, moment.ISO_8601).format("dddd, MMMM Do YYYY, h:mm:ss a")));
ul.append($j('<li/>').text("URL: " + response.url));
ul.append($j('<li/>').text("Duration: " + response.executionTime + " @ " + moment(response.dateTime, moment.ISO_8601).format("dddd, MMMM Do YYYY, h:mm:ss a")));

$j("#webhookDialogAjaxResult").empty().append(ul.html());
console.log(response);
$j("#webhookDialogAjaxResult").empty().append(ul);
},
error: function (response) {
$j('#webhookTestProgress').css("display","none");
Expand Down Expand Up @@ -329,7 +327,7 @@ function populateBuildHistoryAjax(locator) {
locator = '';
}

$j("#webhookPreviewBuildId").empty().append($j('<option></option>').val(null).html("Loading build history..."))
$j("#webhookPreviewBuildId").empty().append($j('<option></option>').val(null).text("Loading build history..."))
$j.ajax ({
url: window['base_uri'] + '/app/rest/builds?locator=' + locator
+ "state:finished&fields=build(id,number,status,finishDate,buildType(id,name))",
Expand All @@ -338,24 +336,21 @@ function populateBuildHistoryAjax(locator) {
'Accept' : 'application/json'
},
success: function (response) {
var myselect = $j('<select>');
myselect.append( $j('<option></option>').val(null).html("Choose a Build...") );
var myselect = $j("#webhookPreviewBuildId");
myselect.empty().append( $j('<option></option>').val(null).text("Choose a Build...") );
$j(response.build).each(function(index, build) {
//console.log(build);
var desc = htmlEscape(build.buildType.name)
+ "#" + build.number
var desc = build.buildType.name
+ "#" + build.number
+ " - " + build.status + " ("
+ moment(build.finishDate, moment.ISO_8601).fromNow()
+ ")";
//console.log(desc);
myselect.append( $j('<option></option>').val(build.id).html(desc) );
myselect.append( $j('<option></option>').val(build.id).text(desc) );
});
$j("#webhookPreviewBuildId").empty().append(myselect.html());
},
error: function (response) {
if (response.status == 404) {
$j("#webhookPreviewBuildId").empty().append(
$j('<option></option>').val(null).html("No builds found. Choose a different project")
$j('<option></option>').val(null).text("No builds found. Choose a different project.")
);
} else {
console.log(response);
Expand Down Expand Up @@ -398,15 +393,15 @@ function toggleAllBuildTypesSelected(){
function updateSelectedBuildTypes(){
var subText = "";
if($j('#buildTypeSubProjects').is(':checked')){
subText = " &amp; sub-projects";
subText = " & sub-projects";
}

if($j('#webHookFormContents input.buildType_single:checked').length == $j('#webHookFormContents input.buildType_single').length){
$j('input.buildType_all').prop('checked', true);
$j('span#selectedBuildCount').html("all" + subText);
$j('span#selectedBuildCount').text("all" + subText);
} else {
$j('input.buildType_all').prop('checked', false);
$j('span#selectedBuildCount').html($j('#webHookFormContents input.buildType_single:checked').length + subText);
$j('span#selectedBuildCount').text($j('#webHookFormContents input.buildType_single:checked').length + subText);
}

}
Expand Down Expand Up @@ -536,22 +531,26 @@ function populateWebHookDialog(id){
$j('#webHookFormContents select#payloadFormatHolder').val(webhook.payloadTemplate + "_" + webhook.payloadFormat).change();

$j('#buildTypeSubProjects').prop('checked', webhook.subProjectsEnabled);
$j.each(webhook.builds, function(){
var thing = $j(this.buildTypeName).text();
console.log(thing);
if (this.enabled){
$j('#buildList').append('<p style="border-bottom:solid 1px #cccccc; margin:0; padding:0.5em;"><label><input checked onclick="updateSelectedBuildTypes();" type=checkbox style="padding-right: 1em;" name="buildTypeId" value="' + this.buildTypeId + '"class="buildType_single">' + htmlEscape(this.buildTypeName) + '</label></p>');
} else {
$j('#buildList').append('<p style="border-bottom:solid 1px #cccccc; margin:0; padding:0.5em;"><label><input onclick="updateSelectedBuildTypes();" type=checkbox style="padding-right: 1em;" name="buildTypeId" value="' + this.buildTypeId + '"class="buildType_single">' + htmlEscape(this.buildTypeName) + '</label></p>');
}
$j.each(webhook.builds, function() {
var isChecked = '';
if (this.enabled) {
isChecked = ' checked';
}
var cbox = $j('<input' + isChecked + ' onclick="updateSelectedBuildTypes();" type=checkbox style="padding-right: 1em;" name="buildTypeId" value="' + this.buildTypeId + '"class="buildType_single">');
var label = $j('<label></label>');
label.text(this.buildTypeName);
label.prepend(cbox);
var container = $j('<p style="border-bottom:solid 1px #cccccc; margin:0; padding:0.5em;"></p>');
container.append(label);
$j('#buildList').append(container);
});

populateWebHookAuthExtrasPane(webhook);
$j('select#extraAuthType').change(function() {
populateWebHookAuthExtrasPaneFromChange(webhook);
});
if ($j('#payloadFormatHolder').val()) {
$j('#currentTemplateName').html(htmlEscape(lookupTemplateName($j('#payloadFormatHolder').val())));
$j('#currentTemplateName').text(lookupTemplateName($j('#payloadFormatHolder').val()));
} else {
$j('#currentTemplateName').html("&nbsp;");
}
Expand Down Expand Up @@ -623,15 +622,6 @@ function lookupAuthParameters(authTypeValue, webHookForm) {
return authParams;
}

function htmlEscape(str) {
return String(str)
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}

function addWebHooksFromJsonCallback(){
var webhookItems = ProjectBuilds.templatesAndWebhooks.projectWebhookConfig.webHookList;
$j.each(webhookItems, function(webHookKey, webhook){
Expand All @@ -643,23 +633,20 @@ function addWebHooksFromJsonCallback(){
.removeClass('webHookRowTemplate')
.addClass('webHookRow');

console.log(webhook.uniqueKey + " :: " + $j("#editWebHookForm input[id='webHookId']").val() );
console.log("addWebHook :: " + $j("#editWebHookForm input[id='submitAction']").val() );

if (webhook.uniqueKey === $j("#editWebHookForm input[id='webHookId']").val() && "addWebHook" === $j("#editWebHookForm input[id='submitAction']").val() ){
isNew = true;
newRow.hide();
}
newRow.appendTo('#webHookTable > tbody');

$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemUrl").html(htmlEscape(webhook.url)).click(function(){WebHooksPlugin.showEditDialog(webhook.uniqueKey, '#hookPane');});
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemUrl").text(webhook.url).click(function(){WebHooksPlugin.showEditDialog(webhook.uniqueKey, '#hookPane');});
if (webhook.payloadTemplate === 'none') {
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemFormat").html(htmlEscape(webhook.payloadFormatForWeb));
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemFormat").text(webhook.payloadFormatForWeb);
} else {
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemFormat").html("<a href='template.html?template=" + webhook.payloadTemplate +"'>" + htmlEscape(webhook.payloadFormatForWeb) + "</a>");
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemFormat").html("").append($j("<a href='template.html?template=" + webhook.payloadTemplate +"'></a>").text(webhook.payloadFormatForWeb));
}
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemEvents").html(webhook.enabledEventsListForWeb).click(function(){WebHooksPlugin.showEditDialog(webhook.uniqueKey,'#hookPane');});
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemBuilds").html(webhook.enabledBuildsListForWeb).click(function(){WebHooksPlugin.showEditDialog(webhook.uniqueKey, '#buildPane');});
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemEvents").text(webhook.enabledEventsListForWeb).click(function(){WebHooksPlugin.showEditDialog(webhook.uniqueKey,'#hookPane');});
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemBuilds").text(webhook.enabledBuildsListForWeb).click(function(){WebHooksPlugin.showEditDialog(webhook.uniqueKey, '#buildPane');});
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemEdit > a").click(function(){WebHooksPlugin.showEditDialog(webhook.uniqueKey,'#hookPane');});
$j("#viewRow_" + webhook.uniqueKey + " > td.webHookRowItemDelete > a").click(function(){WebHooksPlugin.showDeleteDialog(webhook.uniqueKey);});

Expand Down
Loading

0 comments on commit eccd243

Please sign in to comment.