Skip to content

Commit d985b73

Browse files
committed
File import: Do not accept irregular files
1 parent ab72f51 commit d985b73

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dev-master
1515
- [config] Do not override CLI options with profile options
1616
- [node:remove] Cannot `node:remove` by UUID
1717
- [node:edit] Serialization of single value references doesn't work
18+
- [file:import] Irregular files are accepted
1819

1920
### Enhancements
2021

features/all/phpcr_file_import.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Feature: Import an external file as to a node
2727
And I execute the "file:import . phpcr.png" command
2828
Then the command should fail
2929

30+
Scenario: Import non-regular file onto existing file, force not specified
31+
Given I execute the "file:import foo ." command
32+
Then the command should fail
33+
3034
Scenario: Import a file onto existing file, force specified
3135
Given I execute the "file:import . phpcr.png" command
3236
And I execute the "file:import . phpcr.png --force" command

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class ShellApplication extends Application
4545
*/
4646
protected $debug = false;
4747

48+
/**
49+
* @var boolean
50+
*/
51+
protected $initialized = false;
52+
4853
/**
4954
* Constructor - name and version inherited from SessionApplication
5055
*
@@ -56,7 +61,6 @@ public function __construct($container)
5661
$this->dispatcher = $container->get('event.dispatcher') ? : new EventDispatcher();
5762
$this->setDispatcher($this->dispatcher);
5863
$this->container = $container;
59-
$this->init();
6064
}
6165

6266
/**
@@ -75,12 +79,17 @@ public function setShowUnsupported($boolean)
7579
*/
7680
public function init()
7781
{
82+
if (true === $this->initialized) {
83+
return;
84+
}
85+
7886
$this->registerPhpcrCommands();
7987
$this->registerPhpcrStandaloneCommands();
8088
$this->registerShellCommands();
8189

8290
$event = new ApplicationInitEvent($this);
8391
$this->dispatcher->dispatch(PhpcrShellEvents::APPLICATION_INIT, $event);
92+
$this->initialized = true;
8493
}
8594

8695
/**
@@ -219,6 +228,8 @@ private function configureFormatter(OutputFormatter $formatter)
219228
*/
220229
public function doRun(InputInterface $input, OutputInterface $output)
221230
{
231+
$this->init();
232+
222233
// configure the formatter for the output
223234
$this->configureFormatter($output->getFormatter());
224235

src/PHPCR/Shell/Console/Command/Phpcr/NodeFileImportCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public function execute(InputInterface $input, OutputInterface $output)
7070
));
7171
}
7272

73+
if (!is_file($filePath)) {
74+
throw new \InvalidArgumentException(sprintf(
75+
'File "%s" is not a regular file.',
76+
$filePath
77+
));
78+
}
79+
7380
try {
7481
// first assume the user specified the path to the parent node
7582
$parentNode = $this->session->getNode($path);

src/PHPCR/Shell/PhpcrSession.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/PHPCR/Shell/Test/EmbeddedContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function createTester()
2121
$container = new Container(PhpcrShell::MODE_EMBEDDED_SHELL);
2222
$container->get('phpcr.session_manager')->setSession(new PhpcrSession($session));
2323
$application = $container->get('application');
24-
24+
$application->setShowUnsupported(true);
2525
$tester = new ApplicationTester($application);
2626

2727
return $tester;

0 commit comments

Comments
 (0)