8000 Merge pull request #702 from drzraf/raw-filter-empty-string · twigjs/twig.js@326c59e · GitHub
[go: up one dir, main page]

Skip to content

Commit 326c59e

Browse files
authored
Merge pull request #702 from drzraf/raw-filter-empty-string
raw filter on the empty string
2 parents 4ee599d + ae6c641 commit 326c59e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/twig.core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ module.exports = function (Twig) {
14431443
*/
14441444

14451445
Twig.Markup = function (content, strategy) {
1446-
if (typeof content !== 'string' || content.length === 0) {
1446+
if (typeof content !== 'string') {
14471447
return content;
14481448
}
14491449

src/twig.filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ module.exports = function (Twig) {
745745
return value[value.length - 1];
746746
},
747747
raw(value) {
748-
return new Twig.Markup(value);
748+
return new Twig.Markup(value || '');
749749
},
750750
batch(items, params) {
751751
let size = params.shift();

test/test.filters.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,13 @@ describe('Twig.js Filters ->', function () {
778778
value: '<test>&</test>'
779779
}).should.equal('<test>&</test>');
780780
});
781+
782+
it('should output an empty string', function () {
783+
const template = twig({data: '{{ value|raw }}'});
784+
template.render({value: ''}).should.equal('');
785+
template.render({}).should.equal('');
786+
});
787+
781788
});
782789

783790
describe('round ->', function () {

0 commit comments

Comments
 (0)
0