Skip to content

Commit ead5ba3

Browse files
[BUGFIX] check for imageUrls where empty nested arrays returned false positives (kitodo#1706)
Co-authored-by: Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
1 parent 37b1436 commit ead5ba3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Resources/Public/JavaScript/PageView/PageView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ dlfViewer.prototype.displayHighlightWord = function(highlightWords = null) {
832832
*/
833833
dlfViewer.prototype.init = function(controlNames) {
834834

835-
if (this.imageUrls.length <= 0)
835+
if (!dlfUtils.hasContent(this.imageUrls))
836836
throw new Error('Missing image source objects.');
837837

838838
this.initLayer(this.imageUrls)

Resources/Public/JavaScript/PageView/Utility.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,27 @@ dlfUtils.getUrlParam = function (param) {
532532
return null;
533533
};
534534

535+
/**
536+
* Check if an array (possibly nested) contains at least one non-empty value.
537+
*
538+
* @param {Array} arr - The array to check (may be nested).
539+
* @returns {boolean} True if at least one non-empty value exists, false otherwise.
540+
*/
541+
dlfUtils.hasContent = function(arr) {
542+
if (!Array.isArray(arr)) {
543+
return false;
544+
}
545+
546+
return arr.some(item => {
547+
if (Array.isArray(item)) {
548+
// Recurse into nested arrays
549+
return dlfUtils.hasContent(item);
550+
}
551+
// Check primitive values: must not be null/undefined/empty-string
552+
return item !== null && item !== undefined && String(item).trim() !== "";
553+
});
554+
};
555+
535556
/**
536557
* Returns true if the specified value is null.
537558
* @param {?} val

0 commit comments

Comments
 (0)