Commit 110d917
committed
minor #530 Add some checks to the 'pattern' option of Encore.copyFiles() (Lyrkan)
This PR was merged into the master branch.
Discussion
----------
Add some checks to the 'pattern' option of Encore.copyFiles()
While reviewing FriendsOfSymfony/FOSCKEditorBundle#174 I was a bit surprised that calling `copyFiles` with a string as a `pattern` (instead of a `RegExp`) worked fine.
It turns out that's not an issue since the `copyFiles` method causes the creation of a temporary `.js` file in which the `RegExp` is casted to a string anyway.
However, what *is* an issue is that using a string that does not contain a valid regular expression can break that temporary file.
For instance:
```js
Encore.copyFiles({
from: './assets',
pattern: 'foo;'
});
```
Will generate something like:
```js
const context_0 = require.context(
'!/* ... */',
true,
foo; // <= Syntax error here
);
context_0.keys().forEach(context_0);
```
This PR doesn't prevent using strings for that option because I don't think that would be the right choice (the unquoted `/regexp/` syntax may not be obvious for JS beginners) but instead officially allow them with some extra checks.
It also casts `includeSubdirectories` (2nd parameter of the `require.context` above) to a boolean when creating the JS file to avoid the same kind of syntax error.
Commits
-------
d07965c Add some checks to the 'pattern' option of Encore.copyFiles()File tree
4 files changed
+32
-5
lines changed- lib
- test
4 files changed
+32
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
511 | | - | |
512 | | - | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
513 | 514 | | |
514 | 515 | | |
515 | 516 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
474 | 488 | | |
475 | 489 | | |
476 | 490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
426 | | - | |
| 426 | + | |
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
| |||
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
440 | | - | |
| 440 | + | |
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
484 | 496 | | |
485 | 497 | | |
486 | 498 | | |
| |||
0 commit comments