@@ -27,9 +27,9 @@ export class DSONameService {
2727 * With only two exceptions those solutions seem overkill for now.
2828 */
2929 private readonly factories = {
30- EPerson : ( dso : DSpaceObject ) : string => {
31- const firstName = dso . firstMetadataValue ( 'eperson.firstname' ) ;
32- const lastName = dso . firstMetadataValue ( 'eperson.lastname' ) ;
30+ EPerson : ( dso : DSpaceObject , escapeHTML ?: boolean ) : string => {
31+ const firstName = dso . firstMetadataValue ( 'eperson.firstname' , undefined , escapeHTML ) ;
32+ const lastName = dso . firstMetadataValue ( 'eperson.lastname' , undefined , escapeHTML ) ;
3333 if ( isEmpty ( firstName ) && isEmpty ( lastName ) ) {
3434 return this . translateService . instant ( 'dso.name.unnamed' ) ;
3535 } else if ( isEmpty ( firstName ) || isEmpty ( lastName ) ) {
@@ -38,32 +38,33 @@ export class DSONameService {
3838 return `${ firstName } ${ lastName } ` ;
3939 }
4040 } ,
41- Person : ( dso : DSpaceObject ) : string => {
42- const familyName = dso . firstMetadataValue ( 'person.familyName' ) ;
43- const givenName = dso . firstMetadataValue ( 'person.givenName' ) ;
41+ Person : ( dso : DSpaceObject , escapeHTML ?: boolean ) : string => {
42+ const familyName = dso . firstMetadataValue ( 'person.familyName' , undefined , escapeHTML ) ;
43+ const givenName = dso . firstMetadataValue ( 'person.givenName' , undefined , escapeHTML ) ;
4444 if ( isEmpty ( familyName ) && isEmpty ( givenName ) ) {
45- return dso . firstMetadataValue ( 'dc.title' ) || this . translateService . instant ( 'dso.name.unnamed' ) ;
45+ return dso . firstMetadataValue ( 'dc.title' , undefined , escapeHTML ) || this . translateService . instant ( 'dso.name.unnamed' ) ;
4646 } else if ( isEmpty ( familyName ) || isEmpty ( givenName ) ) {
4747 return familyName || givenName ;
4848 } else {
4949 return `${ familyName } , ${ givenName } ` ;
5050 }
5151 } ,
52- OrgUnit : ( dso : DSpaceObject ) : string => {
53- return dso . firstMetadataValue ( 'organization.legalName' ) || this . translateService . instant ( 'dso.name.untitled' ) ;
52+ OrgUnit : ( dso : DSpaceObject , escapeHTML ?: boolean ) : string => {
53+ return dso . firstMetadataValue ( 'organization.legalName' , undefined , escapeHTML ) ;
5454 } ,
55- Default : ( dso : DSpaceObject ) : string => {
55+ Default : ( dso : DSpaceObject , escapeHTML ?: boolean ) : string => {
5656 // If object doesn't have dc.title metadata use name property
57- return dso . firstMetadataValue ( 'dc.title' ) || dso . name || this . translateService . instant ( 'dso.name.untitled' ) ;
58- }
57+ return dso . firstMetadataValue ( 'dc.title' , undefined , escapeHTML ) || dso . name || this . translateService . instant ( 'dso.name.untitled' ) ;
58+ } ,
5959 } ;
6060
6161 /**
6262 * Get the name for the given {@link DSpaceObject}
6363 *
6464 * @param dso The {@link DSpaceObject} you want a name for
65+ * @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
6566 */
66- getName ( dso : DSpaceObject | undefined ) : string {
67+ getName ( dso : DSpaceObject | undefined , escapeHTML ?: boolean ) : string {
6768 if ( dso ) {
6869 const types = dso . getRenderTypes ( ) ;
6970 const match = types
@@ -72,10 +73,10 @@ export class DSONameService {
7273
7374 let name ;
7475 if ( hasValue ( match ) ) {
75- name = this . factories [ match ] ( dso ) ;
76+ name = this . factories [ match ] ( dso , escapeHTML ) ;
7677 }
7778 if ( isEmpty ( name ) ) {
78- name = this . factories . Default ( dso ) ;
79+ name = this . factories . Default ( dso , escapeHTML ) ;
7980 }
8081 return name ;
8182 } else {
@@ -88,27 +89,28 @@ export class DSONameService {
8889 *
8990 * @param object
9091 * @param dso
92+ * @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
9193 *
9294 * @returns {string } html embedded hit highlight.
9395 */
94- getHitHighlights ( object : any , dso : DSpaceObject ) : string {
96+ getHitHighlights ( object : any , dso : DSpaceObject , escapeHTML ?: boolean ) : string {
9597 const types = dso . getRenderTypes ( ) ;
9698 const entityType = types
9799 . filter ( ( type ) => typeof type === 'string' )
98100 . find ( ( type : string ) => ( [ 'Person' , 'OrgUnit' ] ) . includes ( type ) ) as string ;
99101 if ( entityType === 'Person' ) {
100- const familyName = this . firstMetadataValue ( object , dso , 'person.familyName' ) ;
101- const givenName = this . firstMetadataValue ( object , dso , 'person.givenName' ) ;
102+ const familyName = this . firstMetadataValue ( object , dso , 'person.familyName' , escapeHTML ) ;
103+ const givenName = this . firstMetadataValue ( object , dso , 'person.givenName' , escapeHTML ) ;
102104 if ( isEmpty ( familyName ) && isEmpty ( givenName ) ) {
103- return this . firstMetadataValue ( object , dso , 'dc.title' ) || dso . name ;
105+ return this . firstMetadataValue ( object , dso , 'dc.title' , escapeHTML ) || dso . name ;
104106 } else if ( isEmpty ( familyName ) || isEmpty ( givenName ) ) {
105107 return familyName || givenName ;
106108 }
107109 return `${ familyName } , ${ givenName } ` ;
108110 } else if ( entityType === 'OrgUnit' ) {
109- return this . firstMetadataValue ( object , dso , 'organization.legalName' ) || this . translateService . instant ( 'dso.name.untitled' ) ;
111+ return this . firstMetadataValue ( object , dso , 'organization.legalName' , escapeHTML ) ;
110112 }
111- return this . firstMetadataValue ( object , dso , 'dc.title' ) || dso . name || this . translateService . instant ( 'dso.name.untitled' ) ;
113+ return this . firstMetadataValue ( object , dso , 'dc.title' , escapeHTML ) || dso . name || this . translateService . instant ( 'dso.name.untitled' ) ;
112114 }
113115
114116 /**
@@ -117,11 +119,12 @@ export class DSONameService {
117119 * @param object
118120 * @param dso
119121 * @param {string|string[] } keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
122+ * @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
120123 *
121124 * @returns {string } the first matching string value, or `undefined`.
122125 */
123- firstMetadataValue ( object : any , dso : DSpaceObject , keyOrKeys : string | string [ ] ) : string {
124- return Metadata . firstValue ( [ object . hitHighlights , dso . metadata ] , keyOrKeys ) ;
126+ firstMetadataValue ( object : any , dso : DSpaceObject , keyOrKeys : string | string [ ] , escapeHTML ?: boolean ) : string {
127+ return Metadata . firstValue ( dso . metadata , keyOrKeys , object . hitHighlights , undefined , escapeHTML ) ;
125128 }
126129
127130}
0 commit comments