Skip to content

Commit

Permalink
Escape HTML in commit titles (#115)
Browse files Browse the repository at this point in the history
* Escape HTML in commit title while generating changelogs

Do not escape HTML if the user is applying a custom hook on the
changelogs

* Fix lockfile

* Fixed comment

* Removed semicolons
  • Loading branch information
hoodwink73 authored and leo committed Jan 16, 2018
1 parent 9da1d60 commit 2e66623
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 3,602 deletions.
2 changes: 1 addition & 1 deletion bin/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const orderCommits = async (commits, tags, exists) => {

const results = Object.assign({}, predefined, answers)
const grouped = groupChanges(results, changeTypes)
const changes = await createChangelog(grouped, commits, changeTypes)
const changes = await createChangelog(grouped, commits, changeTypes, flags.hook)

let { credits, changelog } = changes

Expand Down
11 changes: 9 additions & 2 deletions lib/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getAuthor = async ({ author }) => {
return username
}

module.exports = async (types, commits, changeTypes) => {
module.exports = async (types, commits, changeTypes, filteringWithHook) => {
let text = ''
const credits = new Set()

Expand All @@ -44,7 +44,14 @@ module.exports = async (types, commits, changeTypes) => {
const lastChange = changes[changes.length - 1]

for (const change of changes) {
const changeDetails = await pickCommit(change, commits.all, changeTypes)
const changeDetails = await pickCommit(
change,
commits.all,
changeTypes,
// Do not escape HTML from commit title
// if a custom hook is being used
!filteringWithHook
)

if (changeDetails.text) {
text += changeDetails.text
Expand Down
11 changes: 8 additions & 3 deletions lib/pick-commit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Packages
const capitalize = require('capitalize')
const escapeGoat = require('escape-goat')

// Utilities
const connect = require('./connect')
Expand Down Expand Up @@ -35,7 +36,7 @@ const forPullRequest = async number => {
return false
}

const cleanCommitTitle = (title, changeTypes) => {
const cleanCommitTitle = (title, changeTypes, doEscapeHTML) => {
const toReplace = {
type: definitions.type(title, changeTypes),
ref: definitions.reference(title)
Expand All @@ -53,14 +54,18 @@ const cleanCommitTitle = (title, changeTypes) => {
}
}

if (doEscapeHTML) {
title = escapeGoat.escape(title)
}

return {
content: capitalize(title).trim(),
ref: toReplace.ref
}
}

module.exports = async ({ hash, message }, all, changeTypes) => {
const title = cleanCommitTitle(message, changeTypes)
module.exports = async ({ hash, message }, all, changeTypes, doEscapeHTML) => {
const title = cleanCommitTitle(message, changeTypes, doEscapeHTML)
let credits = []

if (title.ref) {
Expand Down
Loading

0 comments on commit 2e66623

Please sign in to comment.