Skip to content

Commit

Permalink
fix: non-eager matching raw-block-contents
Browse files Browse the repository at this point in the history
In 4.4.4 the block-contents was matched with an eager match, which means
that with multiple raw-blocks of the same kind, the block was spanned
over the first ending-tag until the last one.
This commit replaces this by a non-eager match.

closes #1579
  • Loading branch information
nknapp committed Oct 20, 2019
1 parent 06edc1f commit 6ed1a80
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion spec/helpers.js
Expand Up @@ -47,10 +47,18 @@ describe('helpers', function() {
runWithIdentityHelper('{{{{identity}}}}{{{{/identity}}}}', '');
});

it('helper for nested raw block works if nested raw blocks are broken', function() {
xit('helper for nested raw block works if nested raw blocks are broken', function() {

This comment has been minimized.

Copy link
@ErisDS

ErisDS Oct 22, 2019

Collaborator

is this maybe a typo?

This comment has been minimized.

Copy link
@nknapp

nknapp Oct 23, 2019

Author Collaborator

No. It's explained in the comment below.

I actually think this should work, but it has never worked and it wasn't critical to this fix. I should probably open an issue as a to do.

// This test was introduced in 4.4.4, but it was not the actual problem that lead to the patch release
// The test is deactivated, because in 3.x this template cases an exception and it also does not work in 4.4.3
// If anyone can make this template work without breaking everything else, then go for it,
// but for now, this is just a known bug, that will be documented.
runWithIdentityHelper('{{{{identity}}}} {{{{a}}}} {{{{ {{{{/ }}}} }}}} {{{{/identity}}}}', ' {{{{a}}}} {{{{ {{{{/ }}}} }}}} ');
});

it('helper for nested raw block closes after first matching close', function() {
runWithIdentityHelper('{{{{identity}}}}abc{{{{/identity}}}} {{{{identity}}}}abc{{{{/identity}}}}', 'abc abc');
});

it('helper for nested raw block throw exception when with missing closing braces', function() {
var string = '{{{{a}}}} {{{{/a';
shouldThrow(function() {
Expand Down
5 changes: 5 additions & 0 deletions spec/tokenizer.js
Expand Up @@ -441,4 +441,9 @@ describe('Tokenizer', function() {
result = tokenize('{{else foo as |bar baz|}}');
shouldMatchTokens(result, ['OPEN_INVERSE_CHAIN', 'ID', 'OPEN_BLOCK_PARAMS', 'ID', 'ID', 'CLOSE_BLOCK_PARAMS', 'CLOSE']);
});

it('tokenizes raw blocks', function() {
var result = tokenize('{{{{a}}}} abc {{{{/a}}}} aaa {{{{a}}}} abc {{{{/a}}}}');
shouldMatchTokens(result, ['OPEN_RAW_BLOCK', 'ID', 'CLOSE_RAW_BLOCK', 'CONTENT', 'END_RAW_BLOCK', 'CONTENT', 'OPEN_RAW_BLOCK', 'ID', 'CLOSE_RAW_BLOCK', 'CONTENT', 'END_RAW_BLOCK']);
});
});
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

1 comment on commit 6ed1a80

@ErisDS
Copy link
Collaborator

@ErisDS ErisDS commented on 6ed1a80 Oct 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Please sign in to comment.