@prismicio/svelte 3.0.0-pr.71.949ea7f → 3.0.0-pr.71.98fd16f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,5 @@
1
- /** Returns `path` if it stays on the current origin, like `/blog?page=2#top`. */
1
+ /**
2
+ * Returns `path` if it stays on the current origin, like `/blog?page=2#top`. It comes from
3
+ * `location`, so it already includes `paths.base`.
4
+ */
2
5
  export declare function getSafePath(path: string | null | undefined): string | undefined;
@@ -1,11 +1,22 @@
1
- /** Returns `path` if it stays on the current origin, like `/blog?page=2#top`. */
1
+ /**
2
+ * Returns `path` if it stays on the current origin, like `/blog?page=2#top`. It comes from
3
+ * `location`, so it already includes `paths.base`.
4
+ */
2
5
  export function getSafePath(path) {
3
6
  if (!path?.startsWith("/") || path.startsWith("//") || path.startsWith("/\\")) {
4
7
  return;
5
8
  }
6
9
  const origin = "https://placeholder.invalid";
7
- const url = new URL(path, origin);
8
- if (url.origin === origin) {
9
- return url.href.slice(origin.length);
10
+ let url;
11
+ try {
12
+ url = new URL(path, origin);
13
+ }
14
+ catch {
15
+ return;
16
+ }
17
+ const safePath = url.href.slice(origin.length);
18
+ // Normalizing can create `//`, like with `/.//example.com`.
19
+ if (url.origin === origin && !safePath.startsWith("//")) {
20
+ return safePath;
10
21
  }
11
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/svelte",
3
- "version": "3.0.0-pr.71.949ea7f",
3
+ "version": "3.0.0-pr.71.98fd16f",
4
4
  "description": "Svelte components to present Prismic content.",
5
5
  "keywords": [
6
6
  "prismic",
@@ -1,12 +1,22 @@
1
- /** Returns `path` if it stays on the current origin, like `/blog?page=2#top`. */
1
+ /**
2
+ * Returns `path` if it stays on the current origin, like `/blog?page=2#top`. It comes from
3
+ * `location`, so it already includes `paths.base`.
4
+ */
2
5
  export function getSafePath(path: string | null | undefined): string | undefined {
3
6
  if (!path?.startsWith("/") || path.startsWith("//") || path.startsWith("/\\")) {
4
7
  return
5
8
  }
6
9
 
7
10
  const origin = "https://placeholder.invalid"
8
- const url = new URL(path, origin)
9
- if (url.origin === origin) {
10
- return url.href.slice(origin.length)
11
+ let url: URL
12
+ try {
13
+ url = new URL(path, origin)
14
+ } catch {
15
+ return
16
+ }
17
+ const safePath = url.href.slice(origin.length)
18
+ // Normalizing can create `//`, like with `/.//example.com`.
19
+ if (url.origin === origin && !safePath.startsWith("//")) {
20
+ return safePath
11
21
  }
12
22
  }