Update GetAnchorUrl in SPService.ts

Solve issue:  
https://github.com/pnp/sp-dev-fx-webparts/issues/3686

fix GetAnchorUrl so it creates correct anchorlink that has a + symbol in the heading.
This commit is contained in:
mikezimm 2023-05-13 01:15:48 -04:00 committed by GitHub
parent 089162f740
commit 6c7ce5883a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -15,10 +15,11 @@ export class SPService {
private static GetAnchorUrl(headingValue: string): string { private static GetAnchorUrl(headingValue: string): string {
let anchorUrl = `#${headingValue let anchorUrl = `#${headingValue
.toLowerCase() .toLowerCase()
.replace(/[{}|\[\]\<\>#@"'^%`?;:\/=~\\\s\s+]/g, " ") .replace(/[{}|\[\]\<\>#@"'^%`?;:\/=~\\\s\s]/g, " ")
.replace(/^(-|\s)*|(-|\s)*$/g, "") .replace(/^(-|\s)*|(-|\s)*$/g, "")
.replace(/\'|\?|\\|\/| |\&/g, "-") .replace(/\'|\?|\\|\/| |\&/g, "-")
.replace(/-+/g, "-") .replace(/-+/g, "-")
.replace(/[+]/g, "%2B") // https://github.com/pnp/sp-dev-fx-webparts/issues/3686
.substring(0, 128)}`; .substring(0, 128)}`;
let counter = 1; let counter = 1;
@ -110,4 +111,4 @@ export class SPService {
return anchorLinks; return anchorLinks;
} }
} }