Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #35 from nicoschoenmaker/feature/module-name-prote…
Browse files Browse the repository at this point in the history
…ction

Protect against odd characters in module name
  • Loading branch information
pjordaan authored Nov 20, 2017
2 parents c989fd8 + a758fa9 commit 633ba2f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/Bundler/Processor/ModuleProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public function peek(string $cwd, ContentState $state): void

public function transpile(string $cwd, ContentItem $item): void
{
$js = "register('" . $item->module_name . "', function (define, require, module, exports) {\n";
$js .= $item->getContent();
$js .= "\n});\n";
$js = "register("
. json_encode($item->module_name, JSON_UNESCAPED_SLASHES)
. ", function (define, require, module, exports) {\n"
. $item->getContent()
. "\n});\n";

$item->transition(ContentState::READY, $js);
}
Expand Down
8 changes: 6 additions & 2 deletions test/Bundler/Processor/ModuleProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ public function testPeek()

public function testTranspile()
{
$item = new ContentItem(new File(basename(__FILE__)), 'foobar.js', new StringReader('console.log("foobar");'));
$item = new ContentItem(
new File(basename(__FILE__)),
'bar/a"/\'/foobar.js',
new StringReader('console.log("foobar");')
);

$this->module_processor->transpile(__DIR__, $item);

self::assertStringEqualsFile(__DIR__ . '/expected.module.js', $item->getContent());
self::assertSame('foobar.js', $item->module_name);
self::assertSame('bar/a"/\'/foobar.js', $item->module_name);
self::assertSame(ContentState::READY, $item->getState()->current());
}
}
2 changes: 1 addition & 1 deletion test/Bundler/Processor/expected.module.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
register('foobar.js', function (define, require, module, exports) {
register("bar/a\"/'/foobar.js", function (define, require, module, exports) {
console.log("foobar");
});

0 comments on commit 633ba2f

Please sign in to comment.