mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX falsey attribute values in shortcodes now work
This commit is contained in:
parent
765f45eaf1
commit
39238d908e
@ -256,7 +256,16 @@ class ShortcodeParser extends Object {
|
|||||||
preg_match_all(static::attrrx(), $match['attrs'][0], $attrmatches, PREG_SET_ORDER);
|
preg_match_all(static::attrrx(), $match['attrs'][0], $attrmatches, PREG_SET_ORDER);
|
||||||
|
|
||||||
foreach ($attrmatches as $attr) {
|
foreach ($attrmatches as $attr) {
|
||||||
list($whole, $name, $value) = array_values(array_filter($attr));
|
$name = '';
|
||||||
|
$value = '';
|
||||||
|
$parts = array_values(array_filter($attr));
|
||||||
|
//the first element in the array is the complete delcaration (`id=1`) - we don't need this
|
||||||
|
array_shift($parts);
|
||||||
|
|
||||||
|
//the next two parts are what we care about (id and 1 from `id=1`)
|
||||||
|
$name = array_shift($parts) ?: $name;
|
||||||
|
$value = array_shift($parts) ?: $value;
|
||||||
|
|
||||||
$attrs[$name] = $value;
|
$attrs[$name] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,6 +224,14 @@ class ShortcodeParserTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFalseyArguments() {
|
||||||
|
$this->parser->parse('<p>[test_shortcode falsey=0]');
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'falsey' => '',
|
||||||
|
), $this->arguments);
|
||||||
|
}
|
||||||
|
|
||||||
public function testNumericShortcodes() {
|
public function testNumericShortcodes() {
|
||||||
$this->assertEqualsIgnoringWhitespace(
|
$this->assertEqualsIgnoringWhitespace(
|
||||||
'[2]',
|
'[2]',
|
||||||
|
Loading…
Reference in New Issue
Block a user