Skip to content

Commit

Permalink
Encoder: removed trailing spaces [Closes #20]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 26, 2015
1 parent c14c3ae commit 5963806
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Neon/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function encode($var, $options = NULL)
foreach ($var as $k => $v) {
$v = $this->encode($v, self::BLOCK);
$s .= ($isList ? '-' : $this->encode($k) . ':')
. (strpos($v, "\n") === FALSE ? ' ' . $v : "\n\t" . str_replace("\n", "\n\t", $v))
. "\n";
continue;
. (strpos($v, "\n") === FALSE
? ' ' . $v . "\n"
: "\n" . preg_replace('#^(?=.)#m', "\t", $v) . (substr($v, -2, 1) === "\n" ? '' : "\n"));
}
return $s;

Expand Down
5 changes: 5 additions & 0 deletions tests/Neon/Encoder.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ Assert::same(
PHP_VERSION_ID >= 50400 ? '",žlu/ťoučký"' : '",\u017elu\/\u0165ou\u010dk\u00fd"',
Neon::encode(',žlu/ťoučký')
);

Assert::same(
"foo: 1\nbar:\n\tx:\n\t\t- 1\n\t\t- 2\n\n\ty:\n\t\t- 3\n\t\t- 4\n\nbaz: null\n",
Neon::encode(array('foo' => 1, 'bar' => array('x' => array(1, 2), 'y' => array(3, 4)), 'baz' => NULL), Neon::BLOCK)
);

0 comments on commit 5963806

Please sign in to comment.