Skip to content
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

fix: prevent zero length tokens in raw-blocks #1577

Merged
merged 2 commits into from Oct 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 28 additions & 7 deletions spec/helpers.js
Expand Up @@ -28,14 +28,35 @@ describe('helpers', function() {
'raw block helper gets raw content');
});

it('helper for nested raw block gets raw content', function() {
var string = '{{{{a}}}} {{{{b}}}} {{{{/b}}}} {{{{/a}}}}';
var helpers = {
a: function(options) {
describe('raw block parsing (with identity helper-function)', function() {

function runWithIdentityHelper(template, expected) {
var helpers = {
identity: function(options) {
return options.fn();
}
};
shouldCompileTo(string, [{}, helpers], ' {{{{b}}}} {{{{/b}}}} ', 'raw block helper should get nested raw block as raw content');
}
};
shouldCompileTo(template, [{}, helpers], expected);
}

it('helper for nested raw block gets raw content', function() {
runWithIdentityHelper('{{{{identity}}}} {{{{b}}}} {{{{/b}}}} {{{{/identity}}}}', ' {{{{b}}}} {{{{/b}}}} ');
});

it('helper for nested raw block works with empty content', function() {
runWithIdentityHelper('{{{{identity}}}}{{{{/identity}}}}', '');
});

it('helper for nested raw block works if nested raw blocks are broken', function() {
runWithIdentityHelper('{{{{identity}}}} {{{{a}}}} {{{{ {{{{/ }}}} }}}} {{{{/identity}}}}', ' {{{{a}}}} {{{{ {{{{/ }}}} }}}} ');
});

it('helper for nested raw block throw exception when with missing closing braces', function() {
var string = '{{{{a}}}} {{{{/a';
shouldThrow(function() {
Handlebars.compile(string)();
});
});
});

it('helper block with identical context', function() {
Expand Down
2 changes: 1 addition & 1 deletion src/handlebars.l
Expand Up @@ -63,7 +63,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD}
return 'END_RAW_BLOCK';
}
}
<raw>[^\x00]*?/("{{{{") { return 'CONTENT'; }
<raw>[^\x00]+/("{{{{") { return 'CONTENT'; }

<com>[\s\S]*?"--"{RIGHT_STRIP}?"}}" {
this.popState();
Expand Down
2 changes: 1 addition & 1 deletion src/handlebars.yy
Expand Up @@ -39,7 +39,7 @@ content
};

rawBlock
: openRawBlock content+ END_RAW_BLOCK -> yy.prepareRawBlock($1, $2, $3, @$)
: openRawBlock content* END_RAW_BLOCK -> yy.prepareRawBlock($1, $2, $3, @$)
;

openRawBlock
Expand Down