Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit 484f083

Browse files
committed
Preventing Javascript
* Preventing Javascript from being executed when added to fields in admin view. * Also found that if several notifications were triggered by a button only first would trigger if it failed without response. Also logging were broken in this case.
1 parent fe0d68f commit 484f083

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
Changelog of Pull Request Notifier for Bitbucket.
44

55
## Unreleased
6+
### GitHub [#132](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/132) How to trigger Jenkins 2.1 with parameters
7+
Better documenting how to trigger Jenkins
8+
9+
[fe0d68fed224d5e](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/fe0d68fed224d5e) Tomas Bjerre *2016-07-31 19:37:11*
10+
11+
### No issue
12+
Preventing Javascript
13+
14+
* Preventing Javascript from being executed when added to fields in admin view.
15+
16+
[1bf663392161c2d](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/1bf663392161c2d) Tomas Bjerre *2016-08-11 17:38:18*
17+
18+
## 2.34
619
### GitHub [#137](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/137) Triigger build button appears in the merged PR view too.
720
Adding PULL_REQUEST_STATE variable
821

9-
[064030fe3420fe0](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/064030fe3420fe0) Tomas Bjerre *2016-07-30 08:48:07*
22+
[2455b339fceebf4](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/2455b339fceebf4) Tomas Bjerre *2016-07-30 08:49:20*
1023

1124
## 2.33
1225
### GitHub [#134](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/134) Not able to see PR buttons

src/main/java/se/bjurr/prnfb/http/UrlInvoker.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ public HttpResponse invoke() {
161161
configureProxy(builder);
162162

163163
this.response = doInvoke(httpRequestBase, builder);
164-
LOG.debug(this.response.getContent());
164+
if (LOG.isDebugEnabled()) {
165+
if (this.response != null) {
166+
LOG.debug(this.response.getContent());
167+
}
168+
}
165169

166170
return this.response;
167171
}
@@ -346,7 +350,9 @@ HttpResponse doInvoke(HttpRequestBase httpRequestBase, HttpClientBuilder builder
346350
LOG.error("", e);
347351
} finally {
348352
try {
349-
httpResponse.close();
353+
if (httpResponse != null) {
354+
httpResponse.close();
355+
}
350356
} catch (IOException e) {
351357
propagate(e);
352358
}

src/main/java/se/bjurr/prnfb/transformer/ButtonTransformer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ public static PrnfbButton toPrnfbButton(ButtonDTO buttonDto) {
4646
public static ButtonPressDTO toTriggerResultDto(PrnfbButton button, List<NotificationResponse> results) {
4747
List<NotificationResponseDTO> notificationResponses = newArrayList();
4848
for (NotificationResponse from : results) {
49-
String content = from.getHttpResponse().getContent();
50-
int status = from.getHttpResponse().getStatus();
49+
String content = null;
50+
int status = 0;
51+
URI uri = null;
52+
if (from.getHttpResponse() != null) {
53+
content = from.getHttpResponse().getContent();
54+
status = from.getHttpResponse().getStatus();
55+
uri = from.getHttpResponse().getUri();
56+
}
5157
UUID notification = from.getNotification();
5258
String notificationName = from.getNotificationName();
53-
URI uri = from.getHttpResponse().getUri();
5459
notificationResponses.add(new NotificationResponseDTO(uri, content, status, notification, notificationName));
5560
}
5661
return new ButtonPressDTO(button.getConfirmation(), notificationResponses);

src/main/resources/pr-triggerbutton.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ define('plugin/prnfb/pr-triggerbutton', [
2323
AJS.flag({
2424
close: 'auto',
2525
type: 'success',
26-
title: notificationResponse.notificationName,
26+
title: notificationResponse.notificationName.replace(/<script>/g,'script'),
2727
body: '<p>You may check network tab in web browser for exact URL and response.</p>'
2828
});
2929
} else {
3030
AJS.flag({
3131
close: 'auto',
3232
type: 'error',
33-
title: notificationResponse.notificationName,
33+
title: notificationResponse.notificationName.replace(/<script>/g,'script'),
3434
body: '<p>' + notificationResponse.status + ' ' + notificationResponse.uri + '</p>' +
35-
'<p>' + notificationResponse.content + '</p>'
35+
'<p>You may check network tab in web browser for exact URL and response.</p>'
3636
});
3737
}
3838
}
@@ -61,7 +61,7 @@ define('plugin/prnfb/pr-triggerbutton', [
6161
function loadSettingsAndShowButtons() {
6262
$.get(buttonsAdminUrl + '/repository/' + pageState.getRepository().id + '/pullrequest/' + pageState.getPullRequest().id, function(settings) {
6363
settings.forEach(function(item) {
64-
var $buttonDropdownItem = buttonTemplate(item.name);
64+
var $buttonDropdownItem = buttonTemplate(item.name.replace(/<script>/g,'script'));
6565
$buttonDropdownItem.click(function() {
6666
var $this = $(this);
6767
$this.attr("disabled", "disabled");
@@ -87,7 +87,7 @@ define('plugin/prnfb/pr-triggerbutton', [
8787
close: 'auto',
8888
type: 'error',
8989
title: "Unknown error",
90-
body: '<p>' + content.status + ' ' + content.statusText + '</p>' + '<p>Check the Bitbucket Server log for more details.</p>'
90+
body: '<p>' + content.status + '</p>' + '<p>Check the Bitbucket Server log for more details.</p>'
9191
});
9292
}
9393
});

src/main/resources/utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ define('plugin/prnfb/utils', [
2222
AJS.messages.error(".statusresponse", {
2323
title: 'Error',
2424
body: '<p>' +
25-
'Sent POST ' + url + ':<br/><code>' + jsonString + '</code><br/><br/>' +
26-
'Got:<br/><code>' + xhr.responseText + '</code><br/><br/>' +
25+
'Sent POST ' + url + ':<br/><code>' + jsonString.replace(/<script>/g,'script') + '</code><br/><br/>' +
26+
'Got:<br/><code>' + xhr.responseText.replace(/<script>/g,'script') + '</code><br/><br/>' +
2727
'</p>'
2828
});
2929
$("html, body").animate({
@@ -204,7 +204,9 @@ define('plugin/prnfb/utils', [
204204
$(formSelector + ' [name=uuid]').empty();
205205
$(formSelector + ' [name=uuid]').append('<option value="">New</option>');
206206
for (var i = 0; i < data.length; i++) {
207-
$(formSelector + ' [name=uuid]').append('<option value="' + data[i].uuid + '">' + (data[i].projectKey || '') + ' ' + (data[i].repositorySlug || '') + ' ' + data[i].name + '</option>');
207+
var name = data[i].name;
208+
name = name.replace(/<script>/g,'script')
209+
$(formSelector + ' [name=uuid]').append('<option value="' + data[i].uuid + '">' + (data[i].projectKey || '') + ' ' + (data[i].repositorySlug || '') + ' ' + name + '</option>');
208210
}
209211
});
210212
clearForm(formSelector);

0 commit comments

Comments
 (0)