diff --git a/src/app/features/files/mappers/file-custom-metadata.mapper.ts b/src/app/features/files/mappers/file-custom-metadata.mapper.ts index a347b32a4..3af893193 100644 --- a/src/app/features/files/mappers/file-custom-metadata.mapper.ts +++ b/src/app/features/files/mappers/file-custom-metadata.mapper.ts @@ -1,13 +1,14 @@ import { ApiData } from '@osf/shared/models/common/json-api.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { FileCustomMetadata, OsfFileCustomMetadata } from '../models'; export function MapFileCustomMetadata(data: ApiData): OsfFileCustomMetadata { return { id: data.id, - description: data.attributes.description, + description: replaceBadEncodedChars(data.attributes.description), language: data.attributes.language, resourceTypeGeneral: data.attributes.resource_type_general, - title: data.attributes.title, + title: replaceBadEncodedChars(data.attributes.title), }; } diff --git a/src/app/features/files/mappers/resource-metadata.mapper.ts b/src/app/features/files/mappers/resource-metadata.mapper.ts index cf89e485d..5fc0e6fc0 100644 --- a/src/app/features/files/mappers/resource-metadata.mapper.ts +++ b/src/app/features/files/mappers/resource-metadata.mapper.ts @@ -1,5 +1,6 @@ import { IdentifiersMapper } from '@osf/shared/mappers/identifiers.mapper'; import { ResourceMetadata } from '@osf/shared/models/resource-metadata.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { GetResourceCustomMetadataResponse } from '../models/get-resource-custom-metadata-response.model'; import { GetResourceShortInfoResponse } from '../models/get-resource-short-info-response.model'; @@ -9,8 +10,8 @@ export function MapResourceMetadata( customMetadata: GetResourceCustomMetadataResponse ): ResourceMetadata { return { - title: shortInfo.data.attributes.title, - description: shortInfo.data.attributes.description, + title: replaceBadEncodedChars(shortInfo.data.attributes.title), + description: replaceBadEncodedChars(shortInfo.data.attributes.description), dateCreated: new Date(shortInfo.data.attributes.date_created), dateModified: new Date(shortInfo.data.attributes.date_modified), funders: diff --git a/src/app/features/meetings/mappers/meetings.mapper.ts b/src/app/features/meetings/mappers/meetings.mapper.ts index 4807257e6..f967aa4bb 100644 --- a/src/app/features/meetings/mappers/meetings.mapper.ts +++ b/src/app/features/meetings/mappers/meetings.mapper.ts @@ -1,4 +1,5 @@ import { ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { MeetingGetResponseJsonApi, @@ -28,7 +29,7 @@ export class MeetingsMapper { return { data: response.data.map((item) => ({ id: item.id, - title: item.attributes.title, + title: replaceBadEncodedChars(item.attributes.title), dateCreated: item.attributes.date_created, authorName: item.attributes.author_name, downloadCount: item.attributes.download_count || 0, diff --git a/src/app/features/metadata/components/metadata-description/metadata-description.component.html b/src/app/features/metadata/components/metadata-description/metadata-description.component.html index f74c20da0..b1dd3143b 100644 --- a/src/app/features/metadata/components/metadata-description/metadata-description.component.html +++ b/src/app/features/metadata/components/metadata-description/metadata-description.component.html @@ -13,6 +13,6 @@

{{ 'project.overview.metadata.description' | translate }}

- {{ (description() | fixSpecialChar) || ('project.overview.metadata.noDescription' | translate) }} + {{ description() || ('project.overview.metadata.noDescription' | translate) }}

diff --git a/src/app/features/metadata/components/metadata-description/metadata-description.component.ts b/src/app/features/metadata/components/metadata-description/metadata-description.component.ts index e7cd92173..27a06c164 100644 --- a/src/app/features/metadata/components/metadata-description/metadata-description.component.ts +++ b/src/app/features/metadata/components/metadata-description/metadata-description.component.ts @@ -5,11 +5,9 @@ import { Card } from 'primeng/card'; import { ChangeDetectionStrategy, Component, input, output } from '@angular/core'; -import { FixSpecialCharPipe } from '@osf/shared/pipes/fix-special-char.pipe'; - @Component({ selector: 'osf-metadata-description', - imports: [Card, Button, FixSpecialCharPipe, TranslatePipe], + imports: [Card, Button, TranslatePipe], templateUrl: './metadata-description.component.html', changeDetection: ChangeDetectionStrategy.OnPush, }) diff --git a/src/app/features/metadata/components/metadata-title/metadata-title.component.html b/src/app/features/metadata/components/metadata-title/metadata-title.component.html index 91a677fd7..9f1e06f1a 100644 --- a/src/app/features/metadata/components/metadata-title/metadata-title.component.html +++ b/src/app/features/metadata/components/metadata-title/metadata-title.component.html @@ -13,6 +13,6 @@

{{ 'common.labels.title' | translate }}

- {{ title() | fixSpecialChar }} + {{ title() }}

diff --git a/src/app/features/metadata/components/metadata-title/metadata-title.component.ts b/src/app/features/metadata/components/metadata-title/metadata-title.component.ts index 5ab4d32ba..b1864575c 100644 --- a/src/app/features/metadata/components/metadata-title/metadata-title.component.ts +++ b/src/app/features/metadata/components/metadata-title/metadata-title.component.ts @@ -5,11 +5,9 @@ import { Card } from 'primeng/card'; import { ChangeDetectionStrategy, Component, input, output } from '@angular/core'; -import { FixSpecialCharPipe } from '@osf/shared/pipes/fix-special-char.pipe'; - @Component({ selector: 'osf-metadata-title', - imports: [Card, Button, FixSpecialCharPipe, TranslatePipe], + imports: [Card, Button, TranslatePipe], templateUrl: './metadata-title.component.html', changeDetection: ChangeDetectionStrategy.OnPush, }) diff --git a/src/app/features/metadata/mappers/metadata.mapper.ts b/src/app/features/metadata/mappers/metadata.mapper.ts index c55d1f5bd..5c166574d 100644 --- a/src/app/features/metadata/mappers/metadata.mapper.ts +++ b/src/app/features/metadata/mappers/metadata.mapper.ts @@ -1,5 +1,6 @@ import { IdentifiersMapper } from '@osf/shared/mappers/identifiers.mapper'; import { LicensesMapper } from '@osf/shared/mappers/licenses.mapper'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { CustomItemMetadataRecord, CustomMetadataJsonApi, MetadataJsonApi, MetadataModel } from '../models'; @@ -7,8 +8,8 @@ export class MetadataMapper { static fromMetadataApiResponse(response: MetadataJsonApi): MetadataModel { return { id: response.id, - title: response.attributes.title, - description: response.attributes.description, + title: replaceBadEncodedChars(response.attributes.title), + description: replaceBadEncodedChars(response.attributes.description), tags: response.attributes.tags, dateCreated: response.attributes.date_created, dateModified: response.attributes.date_modified, diff --git a/src/app/features/moderation/mappers/preprint-moderation.mapper.ts b/src/app/features/moderation/mappers/preprint-moderation.mapper.ts index b87c70438..5fb0cc752 100644 --- a/src/app/features/moderation/mappers/preprint-moderation.mapper.ts +++ b/src/app/features/moderation/mappers/preprint-moderation.mapper.ts @@ -1,6 +1,7 @@ import { UserMapper } from '@osf/shared/mappers/user'; import { ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; import { PaginatedData } from '@osf/shared/models/paginated-data.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { PreprintProviderModerationInfo, @@ -64,7 +65,7 @@ export class PreprintModerationMapper { return { data: response.data.map((x) => ({ id: x.id, - title: x.attributes.title, + title: replaceBadEncodedChars(x.attributes.title), public: x.attributes.public, reviewsState: x.attributes.reviews_state, actions: [], @@ -86,7 +87,7 @@ export class PreprintModerationMapper { return { data: response.data.map((x) => ({ id: x.id, - title: x.embeds.target.data.attributes.title, + title: replaceBadEncodedChars(x.embeds.target.data.attributes.title), preprintId: x.embeds.target.data.id, actions: [], contributors: [], diff --git a/src/app/features/moderation/mappers/registry-moderation.mapper.ts b/src/app/features/moderation/mappers/registry-moderation.mapper.ts index 8c7113170..70ab5fdb4 100644 --- a/src/app/features/moderation/mappers/registry-moderation.mapper.ts +++ b/src/app/features/moderation/mappers/registry-moderation.mapper.ts @@ -1,5 +1,6 @@ import { UserMapper } from '@osf/shared/mappers/user'; import { PaginatedData } from '@osf/shared/models/paginated-data.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { RegistryDataJsonApi, @@ -13,7 +14,7 @@ export class RegistryModerationMapper { static fromResponse(response: RegistryDataJsonApi): RegistryModeration { return { id: response.id, - title: response.attributes.title, + title: replaceBadEncodedChars(response.attributes.title), reviewsState: response.attributes.reviews_state, revisionStatus: response.attributes.revision_state, public: response.attributes.public, diff --git a/src/app/features/preprints/mappers/preprints.mapper.ts b/src/app/features/preprints/mappers/preprints.mapper.ts index 283704403..51ead14da 100644 --- a/src/app/features/preprints/mappers/preprints.mapper.ts +++ b/src/app/features/preprints/mappers/preprints.mapper.ts @@ -2,6 +2,7 @@ import { StringOrNull } from '@osf/shared/helpers/types.helper'; import { IdentifiersMapper } from '@osf/shared/mappers/identifiers.mapper'; import { LicensesMapper } from '@osf/shared/mappers/licenses.mapper'; import { ApiData, JsonApiResponseWithMeta, ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { PreprintAttributesJsonApi, @@ -18,7 +19,7 @@ export class PreprintsMapper { return { data: { attributes: { - title: title, + title: replaceBadEncodedChars(title), description: abstract, }, relationships: { @@ -44,7 +45,7 @@ export class PreprintsMapper { dateWithdrawn: response.attributes.date_withdrawn, datePublished: response.attributes.date_published, dateLastTransitioned: response.attributes.date_last_transitioned, - title: response.attributes.title, + title: replaceBadEncodedChars(response.attributes.title), description: response.attributes.description, reviewsState: response.attributes.reviews_state, preprintDoiCreated: response.attributes.preprint_doi_created, @@ -102,7 +103,7 @@ export class PreprintsMapper { dateWithdrawn: data.attributes.date_withdrawn, datePublished: data.attributes.date_published, dateLastTransitioned: data.attributes.date_last_transitioned, - title: data.attributes.title, + title: replaceBadEncodedChars(data.attributes.title), description: data.attributes.description, reviewsState: data.attributes.reviews_state, preprintDoiCreated: data.attributes.preprint_doi_created, @@ -172,7 +173,7 @@ export class PreprintsMapper { data: response.data.map((preprintData) => { return { id: preprintData.id, - title: preprintData.attributes.title, + title: replaceBadEncodedChars(preprintData.attributes.title), dateModified: preprintData.attributes.date_modified, contributors: preprintData.embeds.bibliographic_contributors.data.map((contrData) => { return { diff --git a/src/app/features/project/settings/mappers/settings.mapper.ts b/src/app/features/project/settings/mappers/settings.mapper.ts index 3dec5f603..d2eef0d1d 100644 --- a/src/app/features/project/settings/mappers/settings.mapper.ts +++ b/src/app/features/project/settings/mappers/settings.mapper.ts @@ -1,6 +1,7 @@ import { UserPermissions } from '@osf/shared/enums/user-permissions.enum'; import { InstitutionsMapper } from '@osf/shared/mappers/institutions'; import { RegionsMapper } from '@osf/shared/mappers/regions'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { BaseNodeDataJsonApi } from '@shared/models/nodes/base-node-data-json-api.model'; import { @@ -30,8 +31,8 @@ export class SettingsMapper { static fromNodeResponse(data: BaseNodeDataJsonApi): NodeDetailsModel { return { id: data.id, - title: data.attributes.title, - description: data.attributes.description, + title: replaceBadEncodedChars(data.attributes.title), + description: replaceBadEncodedChars(data.attributes.description), isPublic: data.attributes.public, region: data.embeds?.region ? RegionsMapper.getRegion(data?.embeds?.region?.data) : null, affiliatedInstitutions: data.embeds?.affiliated_institutions diff --git a/src/app/features/registry/mappers/linked-nodes.mapper.ts b/src/app/features/registry/mappers/linked-nodes.mapper.ts index 441996057..372257e1e 100644 --- a/src/app/features/registry/mappers/linked-nodes.mapper.ts +++ b/src/app/features/registry/mappers/linked-nodes.mapper.ts @@ -1,4 +1,5 @@ import { ContributorsMapper } from '@osf/shared/mappers/contributors'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { LinkedNode, LinkedNodeJsonApi } from '../models'; @@ -6,8 +7,8 @@ export class LinkedNodesMapper { static fromApiResponse(apiNode: LinkedNodeJsonApi): LinkedNode { return { id: apiNode.id, - title: apiNode.attributes.title, - description: apiNode.attributes.description, + title: replaceBadEncodedChars(apiNode.attributes.title), + description: replaceBadEncodedChars(apiNode.attributes.description), category: apiNode.attributes.category, dateCreated: apiNode.attributes.date_created, dateModified: apiNode.attributes.date_modified, diff --git a/src/app/features/registry/mappers/linked-registrations.mapper.ts b/src/app/features/registry/mappers/linked-registrations.mapper.ts index c61b4e7da..72b763e19 100644 --- a/src/app/features/registry/mappers/linked-registrations.mapper.ts +++ b/src/app/features/registry/mappers/linked-registrations.mapper.ts @@ -1,4 +1,5 @@ import { ContributorsMapper } from '@osf/shared/mappers/contributors'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { LinkedRegistration, LinkedRegistrationJsonApi } from '../models'; @@ -6,8 +7,8 @@ export class LinkedRegistrationsMapper { static fromApiResponse(apiRegistration: LinkedRegistrationJsonApi): LinkedRegistration { return { id: apiRegistration.id, - title: apiRegistration.attributes.title, - description: apiRegistration.attributes.description, + title: replaceBadEncodedChars(apiRegistration.attributes.title), + description: replaceBadEncodedChars(apiRegistration.attributes.description), category: apiRegistration.attributes.category, dateCreated: apiRegistration.attributes.date_created, dateModified: apiRegistration.attributes.date_modified, diff --git a/src/app/features/registry/mappers/registry-components.mapper.ts b/src/app/features/registry/mappers/registry-components.mapper.ts index 5e8339323..55ac8b2f6 100644 --- a/src/app/features/registry/mappers/registry-components.mapper.ts +++ b/src/app/features/registry/mappers/registry-components.mapper.ts @@ -1,4 +1,5 @@ import { ContributorsMapper } from '@osf/shared/mappers/contributors'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { RegistryComponentJsonApi, RegistryComponentModel } from '../models'; @@ -6,8 +7,8 @@ export class RegistryComponentsMapper { static fromApiResponse(apiComponent: RegistryComponentJsonApi): RegistryComponentModel { return { id: apiComponent.id, - title: apiComponent.attributes.title, - description: apiComponent.attributes.description, + title: replaceBadEncodedChars(apiComponent.attributes.title), + description: replaceBadEncodedChars(apiComponent.attributes.description), category: apiComponent.attributes.category, dateCreated: apiComponent.attributes.date_created, dateModified: apiComponent.attributes.date_modified, diff --git a/src/app/shared/helpers/format-bad-encoding.helper.ts b/src/app/shared/helpers/format-bad-encoding.helper.ts index 8df1c1d44..ff4a3465b 100644 --- a/src/app/shared/helpers/format-bad-encoding.helper.ts +++ b/src/app/shared/helpers/format-bad-encoding.helper.ts @@ -1,3 +1,4 @@ export function replaceBadEncodedChars(text: string) { + if (!text) return ''; return text.replace(/&/gi, '&').replace(/</gi, '<').replace(/>/gi, '>'); } diff --git a/src/app/shared/mappers/activity-logs.mapper.ts b/src/app/shared/mappers/activity-logs.mapper.ts index d0b7877a6..a4c1fc1c6 100644 --- a/src/app/shared/mappers/activity-logs.mapper.ts +++ b/src/app/shared/mappers/activity-logs.mapper.ts @@ -1,3 +1,5 @@ +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; + import { DEFAULT_TABLE_PARAMS } from '../constants/default-table-params.constants'; import { ActivityLog, LogContributor } from '../models/activity-logs/activity-logs.model'; import { ActivityLogJsonApi, LogContributorJsonApi } from '../models/activity-logs/activity-logs-json-api.model'; @@ -24,7 +26,7 @@ export class ActivityLogsMapper { paramsNode: params.params_node ? { id: params.params_node.id, - title: params.params_node.title, + title: replaceBadEncodedChars(params.params_node.title), } : { id: '', title: '' }, paramsProject: params.params_project, @@ -32,14 +34,14 @@ export class ActivityLogsMapper { ? { id: params.template_node.id, url: params.template_node.url, - title: params.template_node.title, + title: replaceBadEncodedChars(params.template_node.title), } : null, pointer: params.pointer ? { category: params.pointer.category, id: params.pointer.id, - title: params.pointer.title, + title: replaceBadEncodedChars(params.pointer.title), url: params.pointer.url, } : null, @@ -72,8 +74,8 @@ export class ActivityLogsMapper { ? { id: log.embeds.original_node.data.id, type: log.embeds.original_node.data.type, - title: log.embeds.original_node.data.attributes.title, - description: log.embeds.original_node.data.attributes.description, + title: replaceBadEncodedChars(log.embeds.original_node.data.attributes.title), + description: replaceBadEncodedChars(log.embeds.original_node.data.attributes.description), category: log.embeds.original_node.data.attributes.category, customCitation: log.embeds.original_node.data.attributes.custom_citation, dateCreated: log.embeds.original_node.data.attributes.date_created, @@ -119,8 +121,8 @@ export class ActivityLogsMapper { ? { id: log.embeds.linked_node.data.id, type: log.embeds.linked_node.data.type, - title: log.embeds.linked_node.data.attributes.title, - description: log.embeds.linked_node.data.attributes.description, + title: replaceBadEncodedChars(log.embeds.linked_node.data.attributes.title), + description: replaceBadEncodedChars(log.embeds.linked_node.data.attributes.description), category: log.embeds.linked_node.data.attributes.category, customCitation: log.embeds.linked_node.data.attributes.custom_citation, dateCreated: log.embeds.linked_node.data.attributes.date_created, diff --git a/src/app/shared/mappers/collections/collections.mapper.ts b/src/app/shared/mappers/collections/collections.mapper.ts index b0fb73392..88aa46f12 100644 --- a/src/app/shared/mappers/collections/collections.mapper.ts +++ b/src/app/shared/mappers/collections/collections.mapper.ts @@ -20,6 +20,7 @@ import { import { ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; import { ContributorModel } from '@osf/shared/models/contributors/contributor.model'; import { PaginatedData } from '@osf/shared/models/paginated-data.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { UserMapper } from '../user'; @@ -28,8 +29,8 @@ export class CollectionsMapper { return { id: response.id, type: response.type, - name: response.attributes.name, - description: response.attributes.description, + name: replaceBadEncodedChars(response.attributes.name), + description: replaceBadEncodedChars(response.attributes.description), advisoryBoard: response.attributes.advisory_board, example: response.attributes.example, domain: response.attributes.domain, @@ -58,7 +59,7 @@ export class CollectionsMapper { brand: response.embeds.brand.data ? { id: response.embeds.brand.data.id, - name: response.embeds.brand.data.attributes.name, + name: replaceBadEncodedChars(response.embeds.brand.data.attributes.name), heroLogoImageUrl: response.embeds.brand.data.attributes.hero_logo_image, topNavLogoImageUrl: response.embeds.brand.data.attributes.topnav_logo_image, heroBackgroundImageUrl: response.embeds.brand.data.attributes.hero_background_image, @@ -74,7 +75,7 @@ export class CollectionsMapper { return { id: response.id, type: response.type, - title: response.attributes.title, + title: replaceBadEncodedChars(response.attributes.title), dateCreated: response.attributes.date_created, dateModified: response.attributes.date_modified, bookmarks: response.attributes.bookmarks, @@ -110,7 +111,7 @@ export class CollectionsMapper { dataType: submission.attributes.data_type, disease: submission.attributes.disease, gradeLevels: submission.attributes.grade_levels, - collectionTitle: submission.embeds.collection.data.attributes.title, + collectionTitle: replaceBadEncodedChars(submission.embeds.collection.data.attributes.title), collectionId: submission.embeds.collection.data.relationships.provider.data.id, }; } @@ -127,8 +128,8 @@ export class CollectionsMapper { type: submission.type, nodeId: submission.embeds.guid.data.id, nodeUrl: submission.embeds.guid.data.links.html, - title: submission.embeds.guid.data.attributes.title, - description: submission.embeds.guid.data.attributes.description, + title: replaceBadEncodedChars(submission.embeds.guid.data.attributes.title), + description: replaceBadEncodedChars(submission.embeds.guid.data.attributes.description), category: submission.embeds.guid.data.attributes.category, dateCreated: submission.embeds.guid.data.attributes.date_created, dateModified: submission.embeds.guid.data.attributes.date_modified, @@ -183,8 +184,8 @@ export class CollectionsMapper { type: submission.type, nodeId: submission.embeds.guid.data.id, nodeUrl: submission.embeds.guid.data.links.html, - title: submission.embeds.guid.data.attributes.title, - description: submission.embeds.guid.data.attributes.description, + title: replaceBadEncodedChars(submission.embeds.guid.data.attributes.title), + description: replaceBadEncodedChars(submission.embeds.guid.data.attributes.description), category: submission.embeds.guid.data.attributes.category, dateCreated: submission.embeds.guid.data.attributes.date_created, dateModified: submission.embeds.guid.data.attributes.date_modified, diff --git a/src/app/shared/mappers/institutions/institutions.mapper.ts b/src/app/shared/mappers/institutions/institutions.mapper.ts index 56cb294f4..66642d805 100644 --- a/src/app/shared/mappers/institutions/institutions.mapper.ts +++ b/src/app/shared/mappers/institutions/institutions.mapper.ts @@ -4,6 +4,7 @@ import { InstitutionsWithMetaJsonApiResponse, } from '@osf/shared/models/institutions/institution-json-api.model'; import { Institution, InstitutionsWithTotalCount } from '@osf/shared/models/institutions/institutions.models'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; export class InstitutionsMapper { static fromInstitutionsResponse(response: InstitutionsJsonApiResponse): Institution[] { @@ -14,8 +15,8 @@ export class InstitutionsMapper { return { id: data.id, type: data.type, - name: data.attributes.name, - description: data.attributes.description, + name: replaceBadEncodedChars(data.attributes.name), + description: replaceBadEncodedChars(data.attributes.description), iri: data.links.iri, rorIri: data.attributes.ror_iri, iris: data.attributes.iris, diff --git a/src/app/shared/mappers/my-resources.mapper.ts b/src/app/shared/mappers/my-resources.mapper.ts index b924d9a5c..7a2a5d5d2 100644 --- a/src/app/shared/mappers/my-resources.mapper.ts +++ b/src/app/shared/mappers/my-resources.mapper.ts @@ -1,3 +1,5 @@ +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; + import { MyResourcesItem, MyResourcesItemGetResponseJsonApi } from '../models/my-resources/my-resources.models'; import { ContributorsMapper } from './contributors'; @@ -7,7 +9,7 @@ export class MyResourcesMapper { return { id: response.id, type: response.type, - title: response.attributes.title, + title: replaceBadEncodedChars(response.attributes.title), dateCreated: response.attributes.date_created, dateModified: response.attributes.date_modified, isPublic: response.attributes.public, diff --git a/src/app/shared/mappers/nodes/base-node.mapper.ts b/src/app/shared/mappers/nodes/base-node.mapper.ts index e839fcf0f..fa0645bac 100644 --- a/src/app/shared/mappers/nodes/base-node.mapper.ts +++ b/src/app/shared/mappers/nodes/base-node.mapper.ts @@ -3,6 +3,7 @@ import { BaseNodeModel, NodeModel } from '@osf/shared/models/nodes/base-node.mod import { BaseNodeDataJsonApi } from '@osf/shared/models/nodes/base-node-data-json-api.model'; import { NodeShortInfoModel } from '@osf/shared/models/nodes/node-with-children.model'; import { PaginatedData } from '@osf/shared/models/paginated-data.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { ContributorsMapper } from '../contributors'; @@ -22,7 +23,7 @@ export class BaseNodeMapper { static getNodesWithChildren(data: BaseNodeDataJsonApi[], parentId: string): NodeShortInfoModel[] { return this.getAllDescendants(data, parentId).map((item) => ({ id: item.id, - title: item.attributes.title, + title: replaceBadEncodedChars(item.attributes.title), isPublic: item.attributes.public, permissions: item.attributes.current_user_permissions, parentId: item.relationships.parent?.data?.id, @@ -33,8 +34,8 @@ export class BaseNodeMapper { return { id: data.id, type: data.type, - title: data.attributes.title, - description: data.attributes.description, + title: replaceBadEncodedChars(data.attributes.title), + description: replaceBadEncodedChars(data.attributes.description), category: data.attributes.category, dateCreated: data.attributes.date_created, dateModified: data.attributes.date_modified, diff --git a/src/app/shared/mappers/nodes/node-preprint.mapper.ts b/src/app/shared/mappers/nodes/node-preprint.mapper.ts index da9df54bf..700581b8c 100644 --- a/src/app/shared/mappers/nodes/node-preprint.mapper.ts +++ b/src/app/shared/mappers/nodes/node-preprint.mapper.ts @@ -1,11 +1,12 @@ import { NodePreprintModel } from '@osf/shared/models/nodes/node-preprint.model'; import { NodePreprintDataJsonApi } from '@osf/shared/models/nodes/node-preprint-json-api.model'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; export class NodePreprintMapper { static getNodePreprint(data: NodePreprintDataJsonApi): NodePreprintModel { return { id: data.id, - title: data.attributes.title, + title: replaceBadEncodedChars(data.attributes.title), dateCreated: data.attributes.date_created, dateModified: data.attributes.date_modified, datePublished: data.attributes.date_published, diff --git a/src/app/shared/mappers/projects/projects.mapper.ts b/src/app/shared/mappers/projects/projects.mapper.ts index 51cbfa73e..cfe5faf1a 100644 --- a/src/app/shared/mappers/projects/projects.mapper.ts +++ b/src/app/shared/mappers/projects/projects.mapper.ts @@ -2,6 +2,7 @@ import { CollectionSubmissionMetadataPayloadJsonApi } from '@osf/features/collec import { ProjectMetadataUpdatePayload } from '@osf/shared/models/project-metadata-update-payload.model'; import { ProjectModel } from '@osf/shared/models/projects/projects.models'; import { ProjectJsonApi, ProjectsResponseJsonApi } from '@osf/shared/models/projects/projects-json-api.models'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; export class ProjectsMapper { static fromGetAllProjectsResponse(response: ProjectsResponseJsonApi): ProjectModel[] { @@ -12,7 +13,7 @@ export class ProjectsMapper { return { id: project.id, type: project.type, - title: project.attributes.title, + title: replaceBadEncodedChars(project.attributes.title), dateModified: project.attributes.date_modified, isPublic: project.attributes.public, licenseId: project.relationships.license?.data?.id || null, @@ -22,7 +23,7 @@ export class ProjectsMapper { copyrightHolders: project.attributes.node_license.copyright_holders.join(','), } : null, - description: project.attributes.description, + description: replaceBadEncodedChars(project.attributes.description), tags: project.attributes.tags || [], }; } @@ -41,8 +42,8 @@ export class ProjectsMapper { }, }, attributes: { - title: metadata.title, - description: metadata.description, + title: replaceBadEncodedChars(metadata.title), + description: replaceBadEncodedChars(metadata.description), tags: metadata.tags, ...(metadata.licenseOptions && { node_license: { diff --git a/src/app/shared/mappers/registration/page-schema.mapper.ts b/src/app/shared/mappers/registration/page-schema.mapper.ts index 84c57a97f..c42851d43 100644 --- a/src/app/shared/mappers/registration/page-schema.mapper.ts +++ b/src/app/shared/mappers/registration/page-schema.mapper.ts @@ -1,5 +1,6 @@ import { BlockType } from '@osf/shared/enums/block-type.enum'; import { FieldType } from '@osf/shared/enums/field-type.enum'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { PageSchema, Question, Section } from '@shared/models/registration/page-schema.model'; import { SchemaBlocksResponseJsonApi } from '@shared/models/registration/schema-blocks-json-api.model'; @@ -19,7 +20,7 @@ export class PageSchemaMapper { case BlockType.PageHeading: currentPage = { id: item.id, - title: item.attributes.display_text, + title: replaceBadEncodedChars(item.attributes.display_text), helpText: item.attributes.help_text, questions: [], }; @@ -31,7 +32,7 @@ export class PageSchemaMapper { if (currentPage) { currentSection = { id: item.id, - title: item.attributes.display_text, + title: replaceBadEncodedChars(item.attributes.display_text), helpText: item.attributes.help_text, questions: [], }; diff --git a/src/app/shared/mappers/registration/registration-node.mapper.ts b/src/app/shared/mappers/registration/registration-node.mapper.ts index fda7ddd86..9dcafab4d 100644 --- a/src/app/shared/mappers/registration/registration-node.mapper.ts +++ b/src/app/shared/mappers/registration/registration-node.mapper.ts @@ -1,4 +1,5 @@ import { CurrentResourceType } from '@osf/shared/enums/resource-type.enum'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { ProviderShortInfoModel } from '@shared/models/provider/provider.model'; import { RegistryProviderDetailsJsonApi } from '@shared/models/provider/registration-provider-json-api.model'; import { RegistrationNodeModel, RegistrationResponses } from '@shared/models/registration/registration-node.model'; @@ -26,7 +27,7 @@ export class RegistrationNodeMapper { dateModified: attributes.date_modified, dateRegistered: attributes.date_registered, dateWithdrawn: attributes.date_withdrawn, - description: attributes.description, + description: replaceBadEncodedChars(attributes.description), embargoed: attributes.embargoed, embargoEndDate: attributes.embargo_end_date, hasAnalyticCode: attributes.has_analytic_code, @@ -56,7 +57,7 @@ export class RegistrationNodeMapper { reviewsState: attributes.reviews_state, revisionState: attributes.revision_state, tags: attributes.tags || [], - title: attributes.title, + title: replaceBadEncodedChars(attributes.title), wikiEnabled: attributes.wiki_enabled, withdrawalJustification: attributes.withdrawal_justification, withdrawn: attributes.withdrawn, diff --git a/src/app/shared/mappers/registration/registration.mapper.ts b/src/app/shared/mappers/registration/registration.mapper.ts index 966b9fafa..43040ec85 100644 --- a/src/app/shared/mappers/registration/registration.mapper.ts +++ b/src/app/shared/mappers/registration/registration.mapper.ts @@ -1,4 +1,5 @@ import { RegistryStatus } from '@osf/shared/enums/registry-status.enum'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { DraftRegistrationModel } from '@shared/models/registration/draft-registration.model'; import { RegistrationModel } from '@shared/models/registration/registration.model'; import { RegistrationCard } from '@shared/models/registration/registration-card.model'; @@ -17,8 +18,8 @@ export class RegistrationMapper { static fromDraftRegistrationResponse(response: DraftRegistrationDataJsonApi): DraftRegistrationModel { return { id: response.id, - title: response.attributes.title, - description: response.attributes.description, + title: replaceBadEncodedChars(response.attributes.title), + description: replaceBadEncodedChars(response.attributes.description), registrationSchemaId: response.relationships.registration_schema?.data?.id || '', license: { id: response.relationships.license?.data?.id || '', @@ -34,13 +35,13 @@ export class RegistrationMapper { branchedFrom: response.embeds?.branched_from?.data ? { id: response.embeds.branched_from.data.id, - title: response.embeds.branched_from.data.attributes.title, + title: replaceBadEncodedChars(response.embeds.branched_from.data.attributes.title), filesLink: response.embeds?.branched_from?.data.relationships?.files?.links?.related?.href, type: response.embeds.branched_from.data.type, } : { id: response.relationships.branched_from?.data?.id || '', - title: response.attributes.title, + title: replaceBadEncodedChars(response.attributes.title), filesLink: response.relationships.branched_from?.links?.related.href + 'files/', type: response.relationships.branched_from?.data?.type, }, @@ -61,8 +62,8 @@ export class RegistrationMapper { static fromDraftToRegistrationCard(registration: DraftRegistrationDataJsonApi): RegistrationCard { return { id: registration.id, - title: registration.attributes.title, - description: registration.attributes.description || '', + title: replaceBadEncodedChars(registration.attributes.title), + description: replaceBadEncodedChars(registration.attributes.description) || '', status: RegistryStatus.None, dateCreated: registration.attributes.datetime_initiated, dateModified: registration.attributes.datetime_updated, @@ -77,8 +78,8 @@ export class RegistrationMapper { static fromRegistrationToRegistrationCard(registration: RegistrationDataJsonApi): RegistrationCard { return { id: registration.id, - title: registration.attributes.title, - description: registration.attributes.description || '', + title: replaceBadEncodedChars(registration.attributes.title), + description: replaceBadEncodedChars(registration.attributes.description) || '', status: MapRegistryStatus(registration.attributes), dateCreated: registration.attributes.date_created, dateModified: registration.attributes.date_modified, diff --git a/src/app/shared/mappers/search/search.mapper.ts b/src/app/shared/mappers/search/search.mapper.ts index 1ee0cd9a7..e0aad24e9 100644 --- a/src/app/shared/mappers/search/search.mapper.ts +++ b/src/app/shared/mappers/search/search.mapper.ts @@ -1,4 +1,5 @@ import { ResourceType } from '@shared/enums/resource-type.enum'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { IndexCardDataJsonApi, IndexCardSearchResponseJsonApi, @@ -34,7 +35,7 @@ export function MapResources(indexCardSearchResponseJsonApi: IndexCardSearchResp absoluteUrl: resourceMetadata['@id'], resourceType: ResourceType[resourceMetadata.resourceType[0]['@id'] as keyof typeof ResourceType], name: resourceMetadata.name?.[0]?.['@value'], - title: resourceMetadata.title?.[0]?.['@value'], + title: replaceBadEncodedChars(resourceMetadata.title?.[0]?.['@value']), fileName: resourceMetadata.fileName?.[0]?.['@value'], description: resourceMetadata.description?.[0]?.['@value'], diff --git a/src/app/shared/mappers/wiki/wiki.mapper.ts b/src/app/shared/mappers/wiki/wiki.mapper.ts index e79ea6c30..8d16aaedb 100644 --- a/src/app/shared/mappers/wiki/wiki.mapper.ts +++ b/src/app/shared/mappers/wiki/wiki.mapper.ts @@ -11,6 +11,7 @@ import { WikiVersionJsonApi, } from '@osf/shared/models/wiki/wiki.model'; import { ComponentWiki } from '@osf/shared/stores/wiki'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; export class WikiMapper { private static translate: TranslateService; @@ -47,7 +48,7 @@ export class WikiMapper { static fromGetComponentsWikiResponse(response: ComponentsWikiGetResponse): ComponentWiki { return { id: response.id, - title: response.attributes.title, + title: replaceBadEncodedChars(response.attributes.title), list: response.embeds?.wikis?.data.map((wiki) => WikiMapper.fromGetWikiResponse(wiki)) || [], }; }