Skip to content

Commit

Permalink
fix: don't escape html tags inside of inline code in release notes (#…
Browse files Browse the repository at this point in the history
…2367)

Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
mehalter and chingor13 authored Sep 11, 2024
1 parent 050cf93 commit a41d137
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __snapshots__/default-changelog-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ exports['DefaultChangelogNotes buildNotes with commit parsing should handle html
* render all imagesets as &lt;picture&gt; ([383fb14](https://github.com/googleapis/java-asset/commit/383fb14708ae91f7bb7e64bf0bacab38))
`

exports['DefaultChangelogNotes buildNotes with commit parsing should handle html tags as inline code 1'] = `
## [1.2.3](https://github.com/googleapis/java-asset/compare/v1.2.2...v1.2.3) (1983-10-10)
### Features
* render all imagesets as &lt;picture&gt; \`<picture>\` \`\` \`<picture>\` \`\` ([82fcfaf](https://github.com/googleapis/java-asset/commit/82fcfaf039487566a6e2d49a215afe09))
`

exports['DefaultChangelogNotes buildNotes with commit parsing should handle inline bug links 1'] = `
## [1.2.3](https://github.com/googleapis/java-asset/compare/v1.2.2...v1.2.3) (1983-10-10)
Expand Down
4 changes: 3 additions & 1 deletion src/changelog-notes/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,7 @@ function replaceIssueLink(
}

function htmlEscape(message: string): string {
return message.replace('<', '&lt;').replace('>', '&gt;');
return message.replace(/``[^`].*[^`]``|`[^`]*`|<|>/g, match =>
match.length > 1 ? match : match === '<' ? '&lt;' : '&gt;'
);
}
14 changes: 14 additions & 0 deletions test/changelog-notes/default-changelog-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ describe('DefaultChangelogNotes', () => {
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle html tags as inline code', async () => {
const commits = [
buildMockCommit(
'feat: render all imagesets as <picture> `<picture>` `` `<picture>` ``'
),
];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
// it('ignores reverted commits', async () => {
// const commits = [buildCommitFromFixture('multiple-messages')];
// const changelogNotes = new DefaultChangelogNotes();
Expand Down

0 comments on commit a41d137

Please sign in to comment.