1 | import { stringIsNullOrEmpty } from "@pnp/core";
|
2 | /**
|
3 | * Encodes path portions of SharePoint urls such as decodedUrl=`encodePath(pathStr)`
|
4 | *
|
5 | * @param value The string path to encode
|
6 | * @returns A path encoded for use in SP urls
|
7 | */
|
8 | export function encodePath(value) {
|
9 | if (stringIsNullOrEmpty(value)) {
|
10 | return "";
|
11 | }
|
12 | // replace all instance of ' with ''
|
13 | if (/!(@.*?)::(.*?)/ig.test(value)) {
|
14 | return value.replace(/!(@.*?)::(.*)$/ig, (match, labelName, v) => {
|
15 | // we do not need to encodeURIComponent v as it will be encoded automatically when it is added as a query string param
|
16 | // we do need to double any ' chars
|
17 | return `!${labelName}::${v.replace(/'/ig, "''")}`;
|
18 | });
|
19 | }
|
20 | else {
|
21 | // because this is a literal path value we encodeURIComponent after doubling any ' chars
|
22 | return encodeURIComponent(value.replace(/'/ig, "''"));
|
23 | }
|
24 | }
|
25 | //# sourceMappingURL=encode-path-str.js.map |
\ | No newline at end of file |