Skip to content

Commit 5422699

Browse files
Jens Vannerumtdonohue
authored andcommitted
null safety for empty hits for highlight values
1 parent bc48787 commit 5422699

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/app/core/shared/metadata.utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export class Metadata {
4848
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
4949
* @returns {MetadataValue[]} the matching values or an empty array.
5050
*/
51-
public static all(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, escapeHTML?: boolean, limit?: number): MetadataValue[] {
51+
public static all(metadata: MetadataMapInterface = {}, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, escapeHTML?: boolean, limit?: number): MetadataValue[] {
5252
const matches: MetadataValue[] = [];
5353
if (isNotEmpty(hitHighlights)) {
5454
for (const mdKey of Metadata.resolveKeys(hitHighlights, keyOrKeys)) {
5555
if (hitHighlights[mdKey]) {
5656
for (const candidate of hitHighlights[mdKey]) {
5757
if (Metadata.valueMatches(candidate as MetadataValue, filter) && (isEmpty(limit) || (hasValue(limit) && matches.length < limit))) {
58-
const nonHighlightValues = metadata[mdKey] as MetadataValue[];
58+
const nonHighlightValues = metadata?.[mdKey] as MetadataValue[];
5959
const nonHighlightValue = nonHighlightValues?.find((value: MetadataValue) => Metadata.valueMatches(value, filter));
6060
const language = nonHighlightValue?.language ?? candidate.language ?? null;
6161
matches.push(Object.assign(new MetadataValue(), candidate, { language }));
@@ -109,14 +109,14 @@ export class Metadata {
109109
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
110110
* @returns {MetadataValue} the first matching value, or `undefined`.
111111
*/
112-
public static first(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, escapeHTML?: boolean): MetadataValue {
112+
public static first(metadata: MetadataMapInterface = {}, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, escapeHTML?: boolean): MetadataValue {
113113
if (isNotEmpty(hitHighlights)) {
114114
for (const key of Metadata.resolveKeys(hitHighlights, keyOrKeys)) {
115115
const values: MetadataValue[] = hitHighlights[key] as MetadataValue[];
116116
if (values) {
117117
const metadataValue = values.find((value: MetadataValue) => Metadata.valueMatches(value, filter));
118118
if (metadataValue) {
119-
const nonHighlightValues = metadata[key] as MetadataValue[];
119+
const nonHighlightValues = metadata?.[key] as MetadataValue[];
120120
const nonHighlightValue = nonHighlightValues?.find((value: MetadataValue) => Metadata.valueMatches(value, filter));
121121
const language = nonHighlightValue?.language ?? metadataValue.language ?? null;
122122
return Object.assign(new MetadataValue(), metadataValue, { language });

0 commit comments

Comments
 (0)