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

Commit 51f4c60

Browse files
committed
Optionally HTML encode variables in post content #187
* Also adding a .gitattributes to force line endings
1 parent 100d559 commit 51f4c60

File tree

10 files changed

+196
-121
lines changed

10 files changed

+196
-121
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text
2+
3+
*.png binary

CHANGELOG.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@
33
Changelog of Pull Request Notifier for Bitbucket.
44

55
## Unreleased
6+
### GitHub [#187](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/187) Support HTML escaping in variable expansion?
7+
Optionally HTML encode variables in post content
8+
9+
* Also adding a .gitattributes to force line endings
10+
11+
[6c5ea57e189e213](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/6c5ea57e189e213) Tomas Bjerre *2017-01-28 13:24:47*
12+
13+
### No issue
14+
Use table instead of list for variable documentation
15+
16+
[bfea25b36db3cb2](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/bfea25b36db3cb2) Joshua Shearer *2017-01-26 04:05:48*
17+
18+
Fix misspelling
19+
20+
[532d0203e03a92b](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/532d0203e03a92b) Joshua Shearer *2017-01-26 03:46:41*
21+
22+
## 2.48
623
### GitHub [#179](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/179) Add PULL_REQUEST_REVIEWERS_NEEDS_WORK_COUNT
724
NEEDS_WORK and UNAPPROVED variables
825

9-
[7337969c089b16f](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/7337969c089b16f) Tomas Bjerre *2017-01-13 08:20:58*
26+
[85558ecd08f2321](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/85558ecd08f2321) Tomas Bjerre *2017-01-13 08:33:22*
1027

1128
## 2.47
1229
### GitHub [#178](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/178) Forms with checkboxes that have a default value of false do not work
@@ -1036,8 +1053,8 @@ Also:
10361053

10371054
Compatibility with JDK 1.7
10381055

1039-
If you ever consider backward compatibility to be relevant.
1040-
1056+
If you ever consider backward compatibility to be relevant.
1057+
10411058
java.util.Base64 is available since 1.8 and javax.xml.bind.DatatypeConverter since 1.6.
10421059

10431060
[36f99c11d31c763](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/36f99c11d31c763) Raimana *2015-04-01 09:24:20*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ If things don't work as you expect, perhaps you should file an issue. But first,
294294
`curl -u admin:admin 'http://localhost:7990/bitbucket/rest/prnfb-admin/1.0/settings/notifications' -H 'Accept: application/json, text/javascript, */*; q=0.01'`.
295295

296296
`curl -u admin:admin 'http://localhost:7990/bitbucket/rest/prnfb-admin/1.0/settings/buttons' -H 'Accept: application/json, text/javascript, */*; q=0.01'`.
297-
* If the system you are trying to notify does not seem to get notified you may check that the triggered URL looks as expected. You can do that by setting up a webserver, let the plugin invoke that with same parameters and then look at its log files to se the requested URL. Or notify *http://cogi.bjurr.se/?${...}* and I can check my logs and tell you what the URL looks like.
297+
* If the system you are trying to notify does not seem to get notified you may check that the triggered URL looks as expected. You can do that by invoking https://requestb.in/ and inspect its results.
298298

299299
## Developer instructions
300300
There are some scripts to help working with the plugin.

src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,12 @@ public NotificationResponse notify(
220220

221221
Optional<String> postContent = absent();
222222
if (notification.getPostContent().isPresent()) {
223+
ENCODE_FOR encodePostContentFor = notification.getPostContentEncoding();
223224
postContent =
224225
of(
225226
renderer.render(
226227
notification.getPostContent().get(),
227-
ENCODE_FOR.NONE,
228+
encodePostContentFor,
228229
clientKeyStore,
229230
shouldAcceptAnyCertificate));
230231
}

src/main/java/se/bjurr/prnfb/presentation/dto/NotificationDTO.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import javax.xml.bind.annotation.XmlRootElement;
1010

1111
import se.bjurr.prnfb.http.UrlInvoker.HTTP_METHOD;
12+
import se.bjurr.prnfb.service.PrnfbRenderer.ENCODE_FOR;
1213
import se.bjurr.prnfb.settings.TRIGGER_IF_MERGE;
1314

1415
@XmlRootElement
@@ -35,6 +36,11 @@ public class NotificationDTO implements Comparable<NotificationDTO> {
3536
private String url;
3637
private String user;
3738
private UUID uuid;
39+
private ENCODE_FOR postContentEncoding;
40+
41+
public void setPostContentEncoding(ENCODE_FOR postContentEncoding) {
42+
this.postContentEncoding = postContentEncoding;
43+
}
3844

3945
@Override
4046
public int compareTo(NotificationDTO o) {
@@ -283,32 +289,31 @@ public UUID getUuid() {
283289
public int hashCode() {
284290
final int prime = 31;
285291
int result = 1;
286-
result = prime * result + ((this.filterRegexp == null) ? 0 : this.filterRegexp.hashCode());
287-
result = prime * result + ((this.filterString == null) ? 0 : this.filterString.hashCode());
288-
result = prime * result + ((this.headers == null) ? 0 : this.headers.hashCode());
289-
result = prime * result + ((this.injectionUrl == null) ? 0 : this.injectionUrl.hashCode());
292+
result = prime * result + (this.filterRegexp == null ? 0 : this.filterRegexp.hashCode());
293+
result = prime * result + (this.filterString == null ? 0 : this.filterString.hashCode());
294+
result = prime * result + (this.headers == null ? 0 : this.headers.hashCode());
295+
result = prime * result + (this.injectionUrl == null ? 0 : this.injectionUrl.hashCode());
290296
result =
291-
prime * result
292-
+ ((this.injectionUrlRegexp == null) ? 0 : this.injectionUrlRegexp.hashCode());
293-
result = prime * result + ((this.method == null) ? 0 : this.method.hashCode());
294-
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
295-
result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
296-
result = prime * result + ((this.postContent == null) ? 0 : this.postContent.hashCode());
297-
result = prime * result + ((this.projectKey == null) ? 0 : this.projectKey.hashCode());
298-
result = prime * result + ((this.proxyPassword == null) ? 0 : this.proxyPassword.hashCode());
299-
result = prime * result + ((this.proxyPort == null) ? 0 : this.proxyPort.hashCode());
300-
result = prime * result + ((this.proxyServer == null) ? 0 : this.proxyServer.hashCode());
301-
result = prime * result + ((this.proxyUser == null) ? 0 : this.proxyUser.hashCode());
302-
result = prime * result + ((this.repositorySlug == null) ? 0 : this.repositorySlug.hashCode());
297+
prime * result + (this.injectionUrlRegexp == null ? 0 : this.injectionUrlRegexp.hashCode());
298+
result = prime * result + (this.method == null ? 0 : this.method.hashCode());
299+
result = prime * result + (this.name == null ? 0 : this.name.hashCode());
300+
result = prime * result + (this.password == null ? 0 : this.password.hashCode());
301+
result = prime * result + (this.postContent == null ? 0 : this.postContent.hashCode());
302+
result = prime * result + (this.projectKey == null ? 0 : this.projectKey.hashCode());
303+
result = prime * result + (this.proxyPassword == null ? 0 : this.proxyPassword.hashCode());
304+
result = prime * result + (this.proxyPort == null ? 0 : this.proxyPort.hashCode());
305+
result = prime * result + (this.proxyServer == null ? 0 : this.proxyServer.hashCode());
306+
result = prime * result + (this.proxyUser == null ? 0 : this.proxyUser.hashCode());
307+
result = prime * result + (this.repositorySlug == null ? 0 : this.repositorySlug.hashCode());
303308
result =
304-
prime * result + ((this.triggerIfCanMerge == null) ? 0 : this.triggerIfCanMerge.hashCode());
309+
prime * result + (this.triggerIfCanMerge == null ? 0 : this.triggerIfCanMerge.hashCode());
305310
result =
306311
prime * result
307-
+ ((this.triggerIgnoreStateList == null) ? 0 : this.triggerIgnoreStateList.hashCode());
308-
result = prime * result + ((this.triggers == null) ? 0 : this.triggers.hashCode());
309-
result = prime * result + ((this.url == null) ? 0 : this.url.hashCode());
310-
result = prime * result + ((this.user == null) ? 0 : this.user.hashCode());
311-
result = prime * result + ((this.uuid == null) ? 0 : this.uuid.hashCode());
312+
+ (this.triggerIgnoreStateList == null ? 0 : this.triggerIgnoreStateList.hashCode());
313+
result = prime * result + (this.triggers == null ? 0 : this.triggers.hashCode());
314+
result = prime * result + (this.url == null ? 0 : this.url.hashCode());
315+
result = prime * result + (this.user == null ? 0 : this.user.hashCode());
316+
result = prime * result + (this.uuid == null ? 0 : this.uuid.hashCode());
312317
return result;
313318
}
314319

@@ -395,4 +400,8 @@ public void setUser(String user) {
395400
public void setUuid(UUID uuid) {
396401
this.uuid = uuid;
397402
}
403+
404+
public ENCODE_FOR getPostContentEncoding() {
405+
return postContentEncoding;
406+
}
398407
}

src/main/java/se/bjurr/prnfb/service/PrnfbRenderer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import static com.google.common.base.Throwables.propagate;
66
import static java.net.URLEncoder.encode;
77
import static org.slf4j.LoggerFactory.getLogger;
8+
import static se.bjurr.prnfb.service.PrnfbRenderer.ENCODE_FOR.HTML;
89
import static se.bjurr.prnfb.service.PrnfbRenderer.ENCODE_FOR.URL;
910
import static se.bjurr.prnfb.service.PrnfbVariable.EVERYTHING_URL;
1011

1112
import java.io.UnsupportedEncodingException;
1213
import java.util.Map;
1314

15+
import org.apache.commons.lang3.StringEscapeUtils;
1416
import org.slf4j.Logger;
1517

1618
import com.atlassian.bitbucket.pull.PullRequest;
@@ -28,7 +30,8 @@
2830
public class PrnfbRenderer {
2931
public enum ENCODE_FOR {
3032
NONE,
31-
URL
33+
URL,
34+
HTML
3235
}
3336

3437
private static final Logger LOG = getLogger(PrnfbRenderer.class);
@@ -82,6 +85,8 @@ String getRenderedStringResolved(
8285
} catch (UnsupportedEncodingException e) {
8386
propagate(e);
8487
}
88+
} else if (encodeFor == HTML) {
89+
replaceWith = StringEscapeUtils.escapeHtml4(resolved);
8590
} else {
8691
replaceWith = resolved;
8792
}

0 commit comments

Comments
 (0)