Permalink
Browse files

bug #21430 Casting TableCell value to string. (jaydiablo)

This PR was squashed before being merged into the 2.7 branch (closes #21430).

Discussion
----------

Casting TableCell value to string.

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21429
| License       | MIT
| Doc PR        |

PHP throws a catchable fatal error when the value from this method is
used in strstr in the Table class. This fixes the error by casting to a string before returning the value.

Commits
-------

1e5707f Casting TableCell value to string.
  • Loading branch information...
2 parents ff33768 + 1e5707f commit f0d13f47084c3dcb393a6b9d1cea23bf742771ed @fabpot fabpot committed Feb 3, 2017
@@ -35,6 +35,10 @@ class TableCell
*/
public function __construct($value = '', array $options = array())
{
+ if (is_numeric($value) && !is_string($value)) {
+ $value = (string) $value;
+ }
+
$this->value = $value;
// check option names
@@ -543,6 +543,42 @@ public function testRenderMultiByte()
$this->assertEquals($expected, $this->getOutputContent($output));
}
+ public function testTableCellWithNumericIntValue()
+ {
+ $table = new Table($output = $this->getOutputStream());
+
+ $table->setRows(array(array(new TableCell(12345))));
+ $table->render();
+
+ $expected =
+<<<'TABLE'
++-------+
+| 12345 |
++-------+
+
+TABLE;
+
+ $this->assertEquals($expected, $this->getOutputContent($output));
+ }
+
+ public function testTableCellWithNumericFloatValue()
+ {
+ $table = new Table($output = $this->getOutputStream());
+
+ $table->setRows(array(array(new TableCell(12345.01))));
+ $table->render();
+
+ $expected =
+<<<'TABLE'
++----------+
+| 12345.01 |
++----------+
+
+TABLE;
+
+ $this->assertEquals($expected, $this->getOutputContent($output));
+ }
+
public function testStyle()
{
$style = new TableStyle();

0 comments on commit f0d13f4

Please sign in to comment.