Skip to content

Commit fc6bb56

Browse files
committed
fix(comment): detect string end properly
1 parent edfa29b commit fc6bb56

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Comment.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,17 @@ protected function checkTrail(string $char, string $json): string
117117

118118
protected function inStringOrCommentEnd(string $prev, string $char, string $next): bool
119119
{
120-
return $this->inString($char, $prev) || $this->inCommentEnd($next);
120+
return $this->inString($char, $prev, $next) || $this->inCommentEnd($next);
121121
}
122122

123-
protected function inString(string $char, string $prev): bool
123+
protected function inString(string $char, string $prev, string $next): bool
124124
{
125125
if (0 === $this->comment && $char === '"' && $prev !== '\\') {
126-
$this->inStr = !$this->inStr;
126+
return $this->inStr = !$this->inStr;
127+
}
128+
129+
if ($this->inStr && \in_array($next, ['":', '",', '"]', '"}'], true)) {
130+
$this->inStr = false;
127131
}
128132

129133
return $this->inStr;
@@ -200,7 +204,8 @@ public static function parse(string $json, bool $assoc = false, int $depth = 512
200204
public static function parseFromFile(string $file, bool $assoc = false, int $depth = 512, int $options = 0)
201205
{
202206
$json = file_get_contents($file);
203-
204-
return static::parse($json, $assoc, $depth, $options);
207+
echo "\n";
208+
// echo (new static)->strip($json);
209+
return static::parse(trim($json), $assoc, $depth, $options);
205210
}
206211
}

0 commit comments

Comments
 (0)