8000 Throw exception if value is passed to VALUE_NONE input, long syntax · stloyd/symfony@32ea77f · GitHub
[go: up one dir, main page]

Skip to content

Commit 32ea77f

Browse files
committed
Throw exception if value is passed to VALUE_NONE input, long syntax
1 parent ea913e0 commit 32ea77f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private function parseShortOptionSet($name)
134134

135135
break;
136136
} else {
137-
$this->addLongOption($option->getName(), true);
137+
$this->addLongOption($option->getName(), null);
138138
}
139139
}
140140
}
@@ -220,6 +220,10 @@ private function addLongOption($name, $value)
220220
$value = null;
221221
}
222222

223+
if (null !== $value && !$option->acceptValue()) {
224+
throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name, $value));
225+
}
226+
223227
if (null === $value && $option->acceptValue() && count($this->parsed)) {
224228
// if option accepts an optional or mandatory argument
225229
// let's see if there is one provided

src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ public function provideInvalidInput()
175175
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
176176
'The "-o" option does not exist.'
177177
),
178+
array(
179+
array('cli.php', '--foo=bar'),
180+
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
181+
'The "--foo" option does not accept a value.'
182+
),
178183
array(
179184
array('cli.php', 'foo', 'bar'),
180185
new InputDefinition(),

0 commit comments

Comments
 (0)
0