Skip to content

Commit

Permalink
fix(publication softwares): Escape regexp reserved characters
Browse files Browse the repository at this point in the history
  • Loading branch information
folland87 committed Oct 22, 2024
1 parent 97574f7 commit 98fc559
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function PublicationsHeader({ data, authors, affiliations }) {
<section>
<div>
<BadgeGroup>
<Badge color="purple-glycine" noIcon>{publicationTypeMapping[data.type]}</Badge>
{publicationTypeMapping[data.type] && <Badge color="purple-glycine" noIcon>{publicationTypeMapping[data.type]}</Badge>}
<Badge color={data.isOa ? 'green-emeraude' : 'pink-macaron'} icon={data.isOa ? 'lock-unlock-line' : 'lock-line'}>
{intl.formatMessage({ id: `publications.header.oa.${data.isOa ? "true" : "false"}` })}
</Badge>
Expand Down Expand Up @@ -54,4 +54,4 @@ export default function PublicationsHeader({ data, authors, affiliations }) {
</Row>)}
</section>
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ export default function Softwares({ softwares }: { softwares: SoftwareMention[]
const getSoftwareContexts = (softwareName: string, contexts?: string[]) => {
if (!contexts.length) return null;
const newContexts = contexts.map((context) => {
const regexp = new RegExp(softwareName, "ig")
const newContext = context.replace(regexp, `<strong>${softwareName}</strong>`);
return newContext;
const name = softwareName.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&')
try {
const regexp = new RegExp(name, "ig")
const newContext = context.replace(regexp, `<strong>${softwareName}</strong>`);
return newContext;
} catch (e) {
return context;
}
});
const stringContexts = newContexts.reduce((acc, cur) => {
if (acc.length === 0) return cur;
Expand Down Expand Up @@ -84,4 +89,4 @@ export default function Softwares({ softwares }: { softwares: SoftwareMention[]
</Col>
</Row>
);
}
}

0 comments on commit 98fc559

Please sign in to comment.