Skip to content

Commit

Permalink
json - if key empty throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Nov 22, 2023
1 parent 4ad3a32 commit 3e9bf3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/datatypes/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ public function getFeed($url, $settings, $usePrimaryElement = true)
return ['success' => false, 'error' => $error];
}

// if we have empty keys in the array - throw an error, that's not allowed
$containsEmptyKeys = false;
array_walk_recursive($array, function($value, $key) use (&$containsEmptyKeys) {
if (trim($key) === '') {
$containsEmptyKeys = true;
}
});
if ($containsEmptyKeys) {
$error = 'Invalid Data: data contains empty headings (keys)';
Plugin::error($error);
return ['success' => false, 'error' => $error];
}

// If using pagination, set it up here - we need to do this before messing around with the primary element
$this->setupPaginationUrl($array, $settings);

Expand Down
6 changes: 6 additions & 0 deletions src/templates/feeds/_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
<h2>{{ 'Unable to proceed to field mapping'|t('feed-me') }}</h2>
<p>{{ 'Feed Me is unable to find, or parse your provided data. This usually means your URL cannot be reached from your Craft site, or your {feedType} is invalid. Check the logs, and double-check your settings.'|t('feed-me', { feedType: feed.feedType|upper }) }}</p>

{% if feedMappingData.error is not empty %}
<div class="fullpage-error-message">
<code>{{ feedMappingData.error }}</code>
</div>
{% endif %}

<div class="buttons">
<a href="{{ url('feed-me/feeds/' ~ feed.id) }}" class="btn submit">&larr; {{ 'Back to feed'|t('feed-me') }}</a>
<a href="{{ url('feed-me/logs') }}" class="btn submit">{{ 'Go to logs'|t('feed-me') }}</a>
Expand Down

0 comments on commit 3e9bf3a

Please sign in to comment.