Skip to content

Commit 26e14e8

Browse files
author
Bram Maegerman
committed
Merge branch 'w2p-134319_escape-html-tags_contribute-7.6' into w2p-134319_escape-html-tags_contribute-main
2 parents 99bfe13 + d4c8ad0 commit 26e14e8

File tree

22 files changed

+221
-172
lines changed

22 files changed

+221
-172
lines changed

src/app/collection-page/collection-item-mapper/collection-item-mapper.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class CollectionItemMapperComponent implements OnInit {
161161

162162
this.collectionName$ = this.collectionRD$.pipe(
163163
map((rd: RemoteData<Collection>) => {
164-
return this.dsoNameService.getName(rd.payload);
164+
return this.dsoNameService.getName(rd.payload, true);
165165
}),
166166
);
167167
this.searchOptions$ = this.searchConfigService.paginatedSearchOptions;

src/app/core/breadcrumbs/dso-name.service.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe(`DSONameService`, () => {
5454

5555
const result = service.getName(mockPerson);
5656

57-
expect((service as any).factories.Person).toHaveBeenCalledWith(mockPerson);
57+
expect((service as any).factories.Person).toHaveBeenCalledWith(mockPerson, undefined);
5858
expect(result).toBe('Bingo!');
5959
});
6060

@@ -63,7 +63,7 @@ describe(`DSONameService`, () => {
6363

6464
const result = service.getName(mockOrgUnit);
6565

66-
expect((service as any).factories.OrgUnit).toHaveBeenCalledWith(mockOrgUnit);
66+
expect((service as any).factories.OrgUnit).toHaveBeenCalledWith(mockOrgUnit, undefined);
6767
expect(result).toBe('Bingo!');
6868
});
6969

@@ -72,7 +72,7 @@ describe(`DSONameService`, () => {
7272

7373
const result = service.getName(mockDSO);
7474

75-
expect((service as any).factories.Default).toHaveBeenCalledWith(mockDSO);
75+
expect((service as any).factories.Default).toHaveBeenCalledWith(mockDSO, undefined);
7676
expect(result).toBe('Bingo!');
7777
});
7878
});
@@ -86,9 +86,9 @@ describe(`DSONameService`, () => {
8686
it(`should return 'person.familyName, person.givenName'`, () => {
8787
const result = (service as any).factories.Person(mockPerson);
8888
expect(result).toBe(mockPersonName);
89-
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.familyName');
90-
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.givenName');
91-
expect(mockPerson.firstMetadataValue).not.toHaveBeenCalledWith('dc.title');
89+
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.familyName', undefined, undefined);
90+
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.givenName', undefined, undefined);
91+
expect(mockPerson.firstMetadataValue).not.toHaveBeenCalledWith('dc.title', undefined, undefined);
9292
});
9393
});
9494

@@ -100,9 +100,9 @@ describe(`DSONameService`, () => {
100100
it(`should return dc.title`, () => {
101101
const result = (service as any).factories.Person(mockPerson);
102102
expect(result).toBe(mockPersonName);
103-
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.familyName');
104-
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.givenName');
105-
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('dc.title');
103+
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.familyName', undefined, undefined);
104+
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.givenName', undefined, undefined);
105+
expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('dc.title', undefined, undefined);
106106
});
107107
});
108108
});
@@ -115,7 +115,7 @@ describe(`DSONameService`, () => {
115115
it(`should return 'organization.legalName'`, () => {
116116
const result = (service as any).factories.OrgUnit(mockOrgUnit);
117117
expect(result).toBe(mockOrgUnitName);
118-
expect(mockOrgUnit.firstMetadataValue).toHaveBeenCalledWith('organization.legalName');
118+
expect(mockOrgUnit.firstMetadataValue).toHaveBeenCalledWith('organization.legalName', undefined, undefined);
119119
});
120120
});
121121

@@ -127,7 +127,7 @@ describe(`DSONameService`, () => {
127127
it(`should return 'dc.title'`, () => {
128128
const result = (service as any).factories.Default(mockDSO);
129129
expect(result).toBe(mockDSOName);
130-
expect(mockDSO.firstMetadataValue).toHaveBeenCalledWith('dc.title');
130+
expect(mockDSO.firstMetadataValue).toHaveBeenCalledWith('dc.title', undefined, undefined);
131131
});
132132
});
133133
});

src/app/core/breadcrumbs/dso-name.service.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export class DSONameService {
3131
* With only two exceptions those solutions seem overkill for now.
3232
*/
3333
private readonly factories = {
34-
EPerson: (dso: DSpaceObject): string => {
35-
const firstName = dso.firstMetadataValue('eperson.firstname');
36-
const lastName = dso.firstMetadataValue('eperson.lastname');
34+
EPerson: (dso: DSpaceObject, injectedAsHTML?: boolean): string => {
35+
const firstName = dso.firstMetadataValue('eperson.firstname', undefined, injectedAsHTML);
36+
const lastName = dso.firstMetadataValue('eperson.lastname', undefined, injectedAsHTML);
3737
if (isEmpty(firstName) && isEmpty(lastName)) {
3838
return this.translateService.instant('dso.name.unnamed');
3939
} else if (isEmpty(firstName) || isEmpty(lastName)) {
@@ -42,32 +42,33 @@ export class DSONameService {
4242
return `${firstName} ${lastName}`;
4343
}
4444
},
45-
Person: (dso: DSpaceObject): string => {
46-
const familyName = dso.firstMetadataValue('person.familyName');
47-
const givenName = dso.firstMetadataValue('person.givenName');
45+
Person: (dso: DSpaceObject, injectedAsHTML?: boolean): string => {
46+
const familyName = dso.firstMetadataValue('person.familyName', undefined, injectedAsHTML);
47+
const givenName = dso.firstMetadataValue('person.givenName', undefined, injectedAsHTML);
4848
if (isEmpty(familyName) && isEmpty(givenName)) {
49-
return dso.firstMetadataValue('dc.title') || this.translateService.instant('dso.name.unnamed');
49+
return dso.firstMetadataValue('dc.title', undefined, injectedAsHTML) || this.translateService.instant('dso.name.unnamed');
5050
} else if (isEmpty(familyName) || isEmpty(givenName)) {
5151
return familyName || givenName;
5252
} else {
5353
return `${familyName}, ${givenName}`;
5454
}
5555
},
56-
OrgUnit: (dso: DSpaceObject): string => {
57-
return dso.firstMetadataValue('organization.legalName') || this.translateService.instant('dso.name.untitled');
56+
OrgUnit: (dso: DSpaceObject, injectedAsHTML?: boolean): string => {
57+
return dso.firstMetadataValue('organization.legalName', undefined, injectedAsHTML);
5858
},
59-
Default: (dso: DSpaceObject): string => {
59+
Default: (dso: DSpaceObject, injectedAsHTML?: boolean): string => {
6060
// If object doesn't have dc.title metadata use name property
61-
return dso.firstMetadataValue('dc.title') || dso.name || this.translateService.instant('dso.name.untitled');
61+
return dso.firstMetadataValue('dc.title', undefined, injectedAsHTML) || dso.name || this.translateService.instant('dso.name.untitled');
6262
},
6363
};
6464

6565
/**
6666
* Get the name for the given {@link DSpaceObject}
6767
*
6868
* @param dso The {@link DSpaceObject} you want a name for
69+
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
6970
*/
70-
getName(dso: DSpaceObject | undefined): string {
71+
getName(dso: DSpaceObject | undefined, injectedAsHTML?: boolean): string {
7172
if (dso) {
7273
const types = dso.getRenderTypes();
7374
const match = types
@@ -76,10 +77,10 @@ export class DSONameService {
7677

7778
let name;
7879
if (hasValue(match)) {
79-
name = this.factories[match](dso);
80+
name = this.factories[match](dso, injectedAsHTML);
8081
}
8182
if (isEmpty(name)) {
82-
name = this.factories.Default(dso);
83+
name = this.factories.Default(dso, injectedAsHTML);
8384
}
8485
return name;
8586
} else {
@@ -92,27 +93,28 @@ export class DSONameService {
9293
*
9394
* @param object
9495
* @param dso
96+
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
9597
*
9698
* @returns {string} html embedded hit highlight.
9799
*/
98-
getHitHighlights(object: any, dso: DSpaceObject): string {
100+
getHitHighlights(object: any, dso: DSpaceObject, injectedAsHTML?: boolean): string {
99101
const types = dso.getRenderTypes();
100102
const entityType = types
101103
.filter((type) => typeof type === 'string')
102104
.find((type: string) => (['Person', 'OrgUnit']).includes(type)) as string;
103105
if (entityType === 'Person') {
104-
const familyName = this.firstMetadataValue(object, dso, 'person.familyName');
105-
const givenName = this.firstMetadataValue(object, dso, 'person.givenName');
106+
const familyName = this.firstMetadataValue(object, dso, 'person.familyName', injectedAsHTML);
107+
const givenName = this.firstMetadataValue(object, dso, 'person.givenName', injectedAsHTML);
106108
if (isEmpty(familyName) && isEmpty(givenName)) {
107-
return this.firstMetadataValue(object, dso, 'dc.title') || dso.name;
109+
return this.firstMetadataValue(object, dso, 'dc.title', injectedAsHTML) || dso.name;
108110
} else if (isEmpty(familyName) || isEmpty(givenName)) {
109111
return familyName || givenName;
110112
}
111113
return `${familyName}, ${givenName}`;
112114
} else if (entityType === 'OrgUnit') {
113-
return this.firstMetadataValue(object, dso, 'organization.legalName') || this.translateService.instant('dso.name.untitled');
115+
return this.firstMetadataValue(object, dso, 'organization.legalName', injectedAsHTML);
114116
}
115-
return this.firstMetadataValue(object, dso, 'dc.title') || dso.name || this.translateService.instant('dso.name.untitled');
117+
return this.firstMetadataValue(object, dso, 'dc.title', injectedAsHTML) || dso.name || this.translateService.instant('dso.name.untitled');
116118
}
117119

118120
/**
@@ -121,11 +123,12 @@ export class DSONameService {
121123
* @param object
122124
* @param dso
123125
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
126+
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
124127
*
125128
* @returns {string} the first matching string value, or `undefined`.
126129
*/
127-
firstMetadataValue(object: any, dso: DSpaceObject, keyOrKeys: string | string[]): string {
128-
return Metadata.firstValue([object.hitHighlights, dso.metadata], keyOrKeys);
130+
firstMetadataValue(object: any, dso: DSpaceObject, keyOrKeys: string | string[], injectedAsHTML?: boolean): string {
131+
return Metadata.firstValue(dso.metadata, keyOrKeys, object.hitHighlights, undefined, injectedAsHTML);
129132
}
130133

131134
}

src/app/core/shared/dspace-object.model.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,60 +118,64 @@ export class DSpaceObject extends ListableObject implements CacheableObject {
118118
* Gets all matching metadata in this DSpaceObject.
119119
*
120120
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
121-
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
121+
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
122+
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
122123
* @returns {MetadataValue[]} the matching values or an empty array.
123124
*/
124-
allMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): MetadataValue[] {
125-
return Metadata.all(this.metadata, keyOrKeys, valueFilter);
125+
allMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, injectedAsHTML?: boolean): MetadataValue[] {
126+
return Metadata.all(this.metadata, keyOrKeys, undefined, valueFilter, injectedAsHTML);
126127
}
127128

128129
/**
129130
* Like [[allMetadata]], but only returns string values.
130131
*
131132
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
132-
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
133+
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
134+
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
133135
* @returns {string[]} the matching string values or an empty array.
134136
*/
135-
allMetadataValues(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string[] {
136-
return Metadata.allValues(this.metadata, keyOrKeys, valueFilter);
137+
allMetadataValues(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, injectedAsHTML?: boolean): string[] {
138+
return Metadata.allValues(this.metadata, keyOrKeys, undefined, valueFilter, injectedAsHTML);
137139
}
138140

139141
/**
140142
* Gets the first matching MetadataValue object in this DSpaceObject, or `undefined`.
141143
*
142144
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
143-
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
145+
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
146+
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
144147
* @returns {MetadataValue} the first matching value, or `undefined`.
145148
*/
146-
firstMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): MetadataValue {
147-
return Metadata.first(this.metadata, keyOrKeys, valueFilter);
149+
firstMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, injectedAsHTML?: boolean): MetadataValue {
150+
return Metadata.first(this.metadata, keyOrKeys, undefined, valueFilter, injectedAsHTML);
148151
}
149152

150153
/**
151154
* Like [[firstMetadata]], but only returns a string value, or `undefined`.
152155
*
153156
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
154157
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
158+
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
155159
* @returns {string} the first matching string value, or `undefined`.
156160
*/
157-
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
158-
return Metadata.firstValue(this.metadata, keyOrKeys, valueFilter);
161+
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, injectedAsHTML?: boolean): string {
162+
return Metadata.firstValue(this.metadata, keyOrKeys, undefined, valueFilter, injectedAsHTML);
159163
}
160164

161165
/**
162166
* Checks for a matching metadata value in this DSpaceObject.
163167
*
164168
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
165-
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
169+
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
166170
* @returns {boolean} whether a match is found.
167171
*/
168172
hasMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): boolean {
169-
return Metadata.has(this.metadata, keyOrKeys, valueFilter);
173+
return Metadata.has(this.metadata, keyOrKeys, undefined, valueFilter);
170174
}
171175

172176
/**
173177
* Find metadata on a specific field and order all of them using their "place" property.
174-
* @param key
178+
* @param keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
175179
*/
176180
findMetadataSortedByPlace(keyOrKeys: string | string[]): MetadataValue[] {
177181
return this.allMetadata(keyOrKeys).sort((a: MetadataValue, b: MetadataValue) => {

0 commit comments

Comments
 (0)