test
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import sharedEnv from "@shared/env";
|
||||
import parseDocumentSlug from "./parseDocumentSlug";
|
||||
|
||||
sharedEnv.URL = "https://app.outline.dev";
|
||||
|
||||
describe("#parseDocumentSlug", () => {
|
||||
it("should work with fully qualified url", () => {
|
||||
expect(
|
||||
@@ -34,4 +37,10 @@ describe("#parseDocumentSlug", () => {
|
||||
"my-doc-y4j4tR4UuV"
|
||||
);
|
||||
});
|
||||
|
||||
it("should work with path and hash", () => {
|
||||
expect(parseDocumentSlug("/doc/my-doc-y4j4tR4UuV#my-heading-hash")).toEqual(
|
||||
"my-doc-y4j4tR4UuV"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import sharedEnv from "@shared/env";
|
||||
|
||||
/**
|
||||
* Parse the likely document identifier from a given url.
|
||||
*
|
||||
@@ -8,13 +10,13 @@ export default function parseDocumentSlug(url: string) {
|
||||
let parsed;
|
||||
|
||||
if (url[0] === "/") {
|
||||
parsed = url;
|
||||
} else {
|
||||
try {
|
||||
parsed = new URL(url).pathname;
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
url = `${sharedEnv.URL}${url}`;
|
||||
}
|
||||
|
||||
try {
|
||||
parsed = new URL(url).pathname;
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
const split = parsed.split("/");
|
||||
|
||||
Reference in New Issue
Block a user