8000 raw filter on the empty string by drzraf · Pull Request #702 · twigjs/twig.js · GitHub
[go: up one dir, main page]

Skip to content

raw filter on the empty string #702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
The raw filter returns a new Markup(content) which may itself returns…
… the content

 if the content is an empty string or undefined.
The resulting output is [Object] instead of the (expected) empty string.
  • Loading branch information
Raphaël Droz committed Dec 22, 2019
commit ae6c641d4a4a913145e71b97ba81c9c07b2955a5
2 changes: 1 addition & 1 deletion src/twig.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ module.exports = function (Twig) {
*/

Twig.Markup = function (content, strategy) {
if (typeof content !== 'string' || content.length === 0) {
if (typeof content !== 'string') {
return content;
}

Expand Down
2 changes: 1 addition & 1 deletion src/twig.filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ module.exports = function (Twig) {
return value[value.length - 1];
},
raw(value) {
return new Twig.Markup(value);
return new Twig.Markup(value || '');
},
batch(items, params) {
let size = params.shift();
Expand Down
7 changes: 7 additions & 0 deletions test/test.filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ describe('Twig.js Filters ->', function () {
value: '<test>&</test>'
}).should.equal('<test>&</test>');
});

it('should output an empty string', function () {
const template = twig({data: '{{ value|raw }}'});
template.render({value: ''}).should.equal('');
template.render({}).should.equal('');
});

});

describe('round ->', function () {
Expand Down
0