@@ -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 , escapeHTML ?: boolean ) : string => {
35+ const firstName = dso . firstMetadataValue ( 'eperson.firstname' , undefined , escapeHTML ) ;
36+ const lastName = dso . firstMetadataValue ( 'eperson.lastname' , undefined , escapeHTML ) ;
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 , escapeHTML ?: boolean ) : string => {
46+ const familyName = dso . firstMetadataValue ( 'person.familyName' , undefined , escapeHTML ) ;
47+ const givenName = dso . firstMetadataValue ( 'person.givenName' , undefined , escapeHTML ) ;
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 , escapeHTML ) || 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 , escapeHTML ?: boolean ) : string => {
57+ return dso . firstMetadataValue ( 'organization.legalName' , undefined , escapeHTML ) ;
5858 } ,
59- Default : ( dso : DSpaceObject ) : string => {
59+ Default : ( dso : DSpaceObject , escapeHTML ?: 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 , escapeHTML ) || 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 escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
6970 */
70- getName ( dso : DSpaceObject | undefined ) : string {
71+ getName ( dso : DSpaceObject | undefined , escapeHTML ?: 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 , escapeHTML ) ;
8081 }
8182 if ( isEmpty ( name ) ) {
82- name = this . factories . Default ( dso ) ;
83+ name = this . factories . Default ( dso , escapeHTML ) ;
8384 }
8485 return name ;
8586 } else {
@@ -92,27 +93,28 @@ export class DSONameService {
9293 *
9394 * @param object
9495 * @param dso
96+ * @param escapeHTML 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 , escapeHTML ?: 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' , escapeHTML ) ;
107+ const givenName = this . firstMetadataValue ( object , dso , 'person.givenName' , escapeHTML ) ;
106108 if ( isEmpty ( familyName ) && isEmpty ( givenName ) ) {
107- return this . firstMetadataValue ( object , dso , 'dc.title' ) || dso . name ;
109+ return this . firstMetadataValue ( object , dso , 'dc.title' , escapeHTML ) || 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' , escapeHTML ) ;
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' , escapeHTML ) || 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 escapeHTML 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 [ ] , escapeHTML ?: boolean ) : string {
131+ return Metadata . firstValue ( dso . metadata , keyOrKeys , object . hitHighlights , undefined , escapeHTML ) ;
129132 }
130133
131134}
0 commit comments