FIX falsey attribute values in shortcodes now work

This commit is contained in:
Daniel Hensby 2016-07-01 13:39:52 +01:00
parent 765f45eaf1
commit 39238d908e
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 19 additions and 2 deletions

View File

@ -256,7 +256,16 @@ class ShortcodeParser extends Object {
preg_match_all(static::attrrx(), $match['attrs'][0], $attrmatches, PREG_SET_ORDER);
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;
}
}

View File

@ -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() {
$this->assertEqualsIgnoringWhitespace(
'[2]',