Permalink
Browse files

fixes #26:prevent SEGV when calling Sundwon\Base\tableCell

  • Loading branch information...
1 parent 26b77d6 commit 9a86d00af3c7617c72e2cf4dfefc92c8681e1571 @chobie committed Aug 10, 2012
Showing with 58 additions and 6 deletions.
  1. +7 −6 sundown_markdown.c
  2. +51 −0 tests/999-regression-no26.phpt
View
@@ -82,27 +82,28 @@ static void rndr_tablerow(struct buf *ob, const struct buf *text, void *opaque)
static void rndr_tablecell(struct buf *ob, const struct buf *text, int align, void *opaque)
{
- zval php_align;
+ zval *php_align;
+ MAKE_STD_ZVAL(php_align);
switch (align) {
case MKD_TABLE_ALIGN_L:
- ZVAL_STRING(&php_align, "left", 1);
+ ZVAL_STRING(php_align, "left", 1);
break;
case MKD_TABLE_ALIGN_R:
- ZVAL_STRING(&php_align, "right", 1);
+ ZVAL_STRING(php_align, "right", 1);
break;
case MKD_TABLE_ALIGN_CENTER:
- ZVAL_STRING(&php_align, "center", 1);
+ ZVAL_STRING(php_align, "center", 1);
break;
default:
- ZVAL_NULL(&php_align);
+ ZVAL_NULL(php_align);
break;
}
- BLOCK_CALLBACK_EX(ob,"tableCell", 2,buf2str(text), &php_align);
+ BLOCK_CALLBACK_EX(ob, "tableCell", 2, buf2str(text), php_align);
}
/***
@@ -0,0 +1,51 @@
+--TEST--
+Check for https://github.com/chobie/php-sundown/issues/19
+--SKIPIF--
+<?php if (!extension_loaded("sundown")) print "skip"; ?>
+--FILE--
+<?php
+$table = <<<EOS
+| First Header | Second Header |
+| ------------- | ------------- |
+| Content Cell | Content Cell |
+| Content Cell | Content Cell |
+EOS;
+
+//works:
+$sd = new Sundown($table, array('tables'=>true));
+echo $sd->toHTML();
+
+//sementation fault:
+$md = new \Sundown\Markdown(\Sundown\Render\HTML, array('tables'=>true));
+echo $md->render($table);
+--EXPECT--
+<table><thead>
+<tr>
+<th>First Header</th>
+<th>Second Header</th>
+</tr>
+</thead><tbody>
+<tr>
+<td>Content Cell</td>
+<td>Content Cell</td>
+</tr>
+<tr>
+<td>Content Cell</td>
+<td>Content Cell</td>
+</tr>
+</tbody></table>
+<table><thead>
+<tr>
+<td>First Header</td>
+<td>Second Header</td>
+</tr>
+</thead><tbody>
+<tr>
+<td>Content Cell</td>
+<td>Content Cell</td>
+</tr>
+<tr>
+<td>Content Cell</td>
+<td>Content Cell</td>
+</tr>
+</tbody></table>

0 comments on commit 9a86d00

Please sign in to comment.