Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Merge 7c9e84e into adfcfc9
Browse files Browse the repository at this point in the history
  • Loading branch information
lode committed Apr 10, 2019
2 parents adfcfc9 + 7c9e84e commit 5f1f79f
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/Parser/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function load(string $quill_json): Parse
{
$this->quill_json = json_decode($quill_json, true);

if (is_array($this->quill_json) === true && count($this->quill_json) > 0) {
if ($this->isValidDeltaJson($this->quill_json)) {
$this->valid = true;
$this->deltas = [];
return $this;
Expand All @@ -109,7 +109,7 @@ public function loadMultiple(array $quill_json): Parse
foreach ($quill_json as $index => $json) {
$json_stack_value = json_decode($json, true);

if (is_array($json_stack_value) === true && count($json_stack_value) > 0) {
if ($this->isValidDeltaJson($json_stack_value)) {
$this->quill_json_stack[$index] = $json_stack_value;
}
}
Expand Down Expand Up @@ -232,10 +232,7 @@ public function splitOnSingleNewlineOccurrences(string $insert, bool $newlines =
*/
public function parse(): bool
{
if (
$this->valid === true &&
array_key_exists('ops', $this->quill_json) === true
) {
if ($this->valid === true) {
/**
* Before processing through the deltas, generate new deltas by splliting
* on all new lines, will make it much simpler to work out which
Expand Down Expand Up @@ -495,4 +492,26 @@ public function video(array $quill)
{
$this->deltas[] = new $this->class_delta_video($quill['insert']['video']);
}

/**
* Checks the delta json is valid and can be decoded
*
* @param $quill_json Quill json string
*
* @return boolean
*/
private function isValidDeltaJson($quill_json): bool
{
if (is_array($quill_json) === false) {
return false;
}
if (count($quill_json) === 0) {
return false;
}
if (array_key_exists('ops', $quill_json) === false) {
return false;
}

return true;
}
}

0 comments on commit 5f1f79f

Please sign in to comment.