Skip to content

Commit

Permalink
fix(comment): detect string end properly
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Apr 8, 2021
1 parent edfa29b commit fc6bb56
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,17 @@ protected function checkTrail(string $char, string $json): string

protected function inStringOrCommentEnd(string $prev, string $char, string $next): bool
{
return $this->inString($char, $prev) || $this->inCommentEnd($next);
return $this->inString($char, $prev, $next) || $this->inCommentEnd($next);
}

protected function inString(string $char, string $prev): bool
protected function inString(string $char, string $prev, string $next): bool
{
if (0 === $this->comment && $char === '"' && $prev !== '\\') {
$this->inStr = !$this->inStr;
return $this->inStr = !$this->inStr;
}

if ($this->inStr && \in_array($next, ['":', '",', '"]', '"}'], true)) {
$this->inStr = false;
}

return $this->inStr;
Expand Down Expand Up @@ -200,7 +204,8 @@ public static function parse(string $json, bool $assoc = false, int $depth = 512
public static function parseFromFile(string $file, bool $assoc = false, int $depth = 512, int $options = 0)
{
$json = file_get_contents($file);

return static::parse($json, $assoc, $depth, $options);
echo "\n";
// echo (new static)->strip($json);
return static::parse(trim($json), $assoc, $depth, $options);
}
}

0 comments on commit fc6bb56

Please sign in to comment.