Skip to content

Commit

Permalink
fix: newline_to_br filter should output <br /> instead of <br/>, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Mar 13, 2021
1 parent 99d14e7 commit 9a9b792
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/builtin/filters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function escapeOnce (str: string) {
}

export function newlineToBr (v: string) {
return v.replace(/\n/g, '<br/>')
return v.replace(/\n/g, '<br />\n')
}

export function stripHtml (v: string) {
Expand Down
9 changes: 8 additions & 1 deletion test/e2e/issues.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Liquid } from '../..'
import { Liquid } from '../../src/liquid'
import { Liquid as LiquidUMD } from '../../dist/liquid.browser.umd.js'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
Expand Down Expand Up @@ -95,4 +95,11 @@ describe('Issues', function () {
)
expect(html).to.equal('falsefalse')
})
it('#321 comparison for empty/nil', async () => {
const engine = new Liquid()
const html = await engine.parseAndRender(
`{{ 'a \n b \n c' | newline_to_br | split: '<br />' }}`
)
expect(html).to.equal('a ,\n b ,\n c')
})
})
6 changes: 3 additions & 3 deletions test/integration/builtin/filters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ describe('filters/html', function () {
'there\n' +
'{% endcapture %}' +
'{{ string_with_newlines | newline_to_br }}'
const dst = '<br/>' +
'Hello<br/>' +
'there<br/>'
const dst = '<br />\n' +
'Hello<br />\n' +
'there<br />\n'
return test(src, dst)
})
})
Expand Down

0 comments on commit 9a9b792

Please sign in to comment.