Skip to content

Commit

Permalink
fix: Append a newline terminator on the last line of the generated file
Browse files Browse the repository at this point in the history
Terminate the generated file with a newline, even the last line, to make those files compliant with 3.3 of the current draft of the specification.

#36
  • Loading branch information
joker314 authored Oct 29, 2018
1 parent 7d295f6 commit f48bfe2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions __tests__/formatPolicy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('formats successfully with correct fields (singular contact field)', () =>
'Contact: [email protected]\n' +
'Encryption: https://www.mykey.com/pgp-key.txt\n' +
'Acknowledgement: thank you\n' +
'Permission: none'
'Permission: none\n'
)
})

Expand All @@ -26,7 +26,7 @@ test('formats successfully with mandatory field only', () => {
const res = securityTxt.formatSecurityPolicy(options)

expect(res).toBe(
'Contact: [email protected]'
'Contact: [email protected]\n'
)
})

Expand Down Expand Up @@ -54,7 +54,7 @@ test('formats successfully with multiple contact options and values in-tact', ()
`Contact: ${website}\n` +
`Contact: ${phone}\n` +
`Encryption: ${encryption}\n` +
`Acknowledgement: ${acknowledgement}`
`Acknowledgement: ${acknowledgement}\n`
)
})

Expand All @@ -72,7 +72,7 @@ test('formats successfully with policy, hiring and signature fields', () => {
'Contact: [email protected]\n' +
'Signature: http://example.com/.well-known/signature.txt.sig\n' +
'Policy: http://example.com/policy.txt\n' +
'Hiring: http://example.com/hiring.txt'
'Hiring: http://example.com/hiring.txt\n'
)
})

Expand All @@ -86,6 +86,6 @@ test('formats successfully with "none" not in lowercase for Permission: directiv

expect(res).toBe(
'Contact: [email protected]\n' +
'Permission: NoNe'
'Permission: NoNe\n'
)
})
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ class middleware {
}

const tmpPolicyArray = []
for (const [field, value] of Object.entries(policySetting)) {
if (typeof value === 'object') {
value.forEach(valueOption => {
tmpPolicyArray.push(`${field}: ${valueOption}`)
})
} else {
tmpPolicyArray.push(`${field}: ${value}`)
for (let [field, value] of Object.entries(policySetting)) {
if (typeof value !== 'object') {
value = [ value ]
}

value.forEach(valueOption => {
tmpPolicyArray.push(`${field}: ${valueOption}\n`)
})
}

policySettingText = tmpPolicyArray.join('\n')
policySettingText = tmpPolicyArray.join('')
return policySettingText
}

Expand Down

0 comments on commit f48bfe2

Please sign in to comment.