test(theme): add tests for escaping of single and double quotes

pull/144/merge
Romain 5 years ago
parent 282cf26473
commit 2e875e7448

@ -2,10 +2,7 @@ const path = require('path')
module.exports = (target, options) => {
const albumPath = options.data.root.album.path
var relative = path.relative(path.dirname(albumPath), target)
const relative = path.relative(path.dirname(albumPath), target)
// Escape single/double quotes
var escaped = relative.replace(/'/g, '%27')
escaped = escaped.replace(/"/g, '%22')
return escaped
return relative.replace(/'/g, '%27').replace(/"/g, '%22')
}

@ -24,4 +24,26 @@ describe('Handlebars helpers: relative', () => {
})
should(res).eql('<link rel="stylesheet" href="../public/theme.css" />')
})
it('escapes single quotes so they can be used in CSS background-image', () => {
const template = handlebars.compile(`background-image('{{relative url}}')`)
const res = template({
url: "l'histoire.jpg",
album: {
path: 'index.html'
}
})
should(res).eql("background-image('l%27histoire.jpg')")
})
it('escapes double quotes so they can be used in <img> tags', () => {
const template = handlebars.compile(`<img src="{{relative url}}" />`)
const res = template({
url: 'l"histoire.jpg',
album: {
path: 'index.html'
}
})
should(res).eql('<img src="l%22histoire.jpg" />')
})
})

Loading…
Cancel
Save