Skip to content

Commit

Permalink
fix(html-sanitize): Sanitize HTML comments in PR (#4285)
Browse files Browse the repository at this point in the history
Sanitizes HTML comments inside PR body for BitBucket server.
Includes snapshots for the tests.

Closes #3715
  • Loading branch information
rakeshtembhurne authored and rarkins committed Aug 14, 2019
1 parent 8e20aa0 commit 4ee030a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ export function getPrBody(input: string) {
.replace(/<\/?summary>/g, '**')
.replace(/<\/?details>/g, '')
.replace(new RegExp(`\n---\n\n.*?<!-- .*?-rebase -->.*?(\n|$)`), '')
.replace(new RegExp('<!--.*?-->', 'g'), '')
.substring(0, 30000);
}

Expand Down
28 changes: 28 additions & 0 deletions test/platform/bitbucket-server/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,20 @@ exports[`platform/bitbucket-server endpoint with no path getPr() returns null fo

exports[`platform/bitbucket-server endpoint with no path getPrBody() returns diff files 1`] = `"**foo**bartext"`;

exports[`platform/bitbucket-server endpoint with no path getPrBody() sanitizes HTML comments in the body 1`] = `
"---
- [ ] If you want to rebase/retry this PR, check this box
- [ ] <a href=\\"/some/link\\">Update renovate/renovate to 16.1.2</a>
---
Empty comment.
Followed by some information.
"
`;
exports[`platform/bitbucket-server endpoint with no path getPrFiles() returns one file 1`] = `
Array [
Array [
Expand Down Expand Up @@ -2381,6 +2395,20 @@ exports[`platform/bitbucket-server endpoint with path getPr() returns null for n
exports[`platform/bitbucket-server endpoint with path getPrBody() returns diff files 1`] = `"**foo**bartext"`;
exports[`platform/bitbucket-server endpoint with path getPrBody() sanitizes HTML comments in the body 1`] = `
"---
- [ ] If you want to rebase/retry this PR, check this box
- [ ] <a href=\\"/some/link\\">Update renovate/renovate to 16.1.2</a>
---
Empty comment.
Followed by some information.
"
`;
exports[`platform/bitbucket-server endpoint with path getPrFiles() returns one file 1`] = `
Array [
Array [
Expand Down
15 changes: 15 additions & 0 deletions test/platform/bitbucket-server/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,21 @@ describe('platform/bitbucket-server', () => {
)
).toMatchSnapshot();
});

it('sanitizes HTML comments in the body', () => {
const prBody = bitbucket.getPrBody(`---
- [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box
- [ ] <!-- recreate-branch=renovate/docker-renovate-renovate-16.x --><a href="/some/link">Update renovate/renovate to 16.1.2</a>
---
<!---->
Empty comment.
<!-- This is another comment -->
Followed by some information.
<!-- followed by some more comments -->`);
expect(prBody).toMatchSnapshot();
});
});

describe('getCommitMessages()', () => {
Expand Down

0 comments on commit 4ee030a

Please sign in to comment.