Skip to content

Commit

Permalink
Merge pull request #37 from localheinz/fix/indent
Browse files Browse the repository at this point in the history
Fix: Reject mixed tabs and spaces as indent
  • Loading branch information
localheinz authored Aug 11, 2018
2 parents 74243e7 + d09b305 commit 6e11e5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function print(string $json, string $indent = ' ', string $newLine = \
));
}

if (1 !== \preg_match('/^[ \t]+$/', $indent)) {
if (1 !== \preg_match('/^( +|\t+)$/', $indent)) {
throw new \InvalidArgumentException(\sprintf(
'"%s" is not a valid indent.',
$indent
Expand Down
5 changes: 3 additions & 2 deletions test/Unit/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ public function testPrintRejectsInvalidIndent(string $indent)
public function providerInvalidIndent(): \Generator
{
$values = [
'not-whitespace' => $this->faker()->sentence,
'contains-line-feed' => " \n ",
'string-contains-line-feed' => " \n ",
'string-mixed-space-and-tab' => " \t",
'string-not-whitespace' => $this->faker()->sentence,
];

foreach ($values as $key => $value) {
Expand Down

0 comments on commit 6e11e5c

Please sign in to comment.