8000 Merge pull request #824 from willrowe/compatibility/path/preserve-whi… · twigjs/twig.js@c94a117 · GitHub
[go: up one dir, main page]

Skip to content

Commit c94a117

Browse files
authored
Merge pull request #824 from willrowe/compatibility/path/preserve-whitespace
Add tests for whitespace in paths
2 parents 03c47bc + 6894f12 commit c94a117

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

test/test.fs.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,49 @@ describe('Twig.js Include ->', function () {
161161
rethrow: true
162162
});
163163
});
164+
165+
it('should include paths with trailing or leading whitespace', function () {
166+
twig({
167+
'data': 'path has leading whitespace',
168+
'id': ' path/with/leading/whitespace.twig',
169+
});
170+
twig({
171+
'data': 'path has trailing whitespace',
172+
'id': 'path/with/trailing/whitespace.twig ',
173+
});
174+
175+
twig({
176+
'allowInlineIncludes': true,
177+
'data': "{% include ' path/with/leading/whitespace.twig' %} - {% include 'path/with/trailing/whitespace.twig ' %}",
178+
}).render().trim().should.equal('path has leading whitespace - path has trailing whitespace');
179+
});
180+
181+
it('should not include paths without trailing or leading whitespace', function () {
182+
twig({
183+
'data': 'path has no leading whitespace',
184+
'id': 'path/without/leading/whitespace.twig',
185+
});
186+
twig({
187+
'data': 'path has no trailing whitespace',
188+
'id': 'path/without/trailing/whitespace.twig',
189+
});
190+
191+
(function () {
192+
twig({
193+
'allowInlineIncludes': true,
194+
'data': "{% include ' path/without/leading/whitespace.twig' %}",
195+
'rethrow': true,
196+
}).render();
197+
}).should.throw(/Unable to find template file/);
198+
199+
(function () {
200+
twig({
201+
'allowInlineIncludes': true,
202+
'data': "{% include 'path/without/trailing/whitespace.twig ' %}",
203+
'rethrow': true,
204+
}).render();
205+
}).should.throw(/Unable to find template file/);
206+
});
164207
});
165208

166209
describe('Twig.js Extends ->', function () {
@@ -193,4 +236,4 @@ describe('Twig.js Extends ->', function () {
193236
const output = template.render();
194237
output.trim().should.equal('Nothing to see here');
195238
});
196-
});
239+
});

0 commit comments

Comments
 (0)
0