Skip to content

Commit

Permalink
Fixes potential issues when editing slug.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShindouMihou committed Jul 1, 2022
1 parent 806d334 commit 660e5ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/lib/components/editor/FloraEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@
axios
.get("/api/posts/" + postId)
.then((result) => {
postId = result.data._id;
image = result.data.image;
title = result.data.title;
content = result.data.content;
published = result.data.published;
slug = result.data.slug ?? "";
let url = new URL(window.location.toString());
url.pathname = "/editor/" + postId;
window.history.pushState({}, "", url);
initialLoading = true;
})
.catch((error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/posts/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function post(event: RequestEvent) {
softClone.published = body.published;
}

if (softClone.slug != null) {
if (softClone.slug) {
softClone.slug = encodeURI(softClone.slug)
}

Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function put(event: RequestEvent) {
return FloraicResponses.INVALID_REQUEST;

let slug: string | null = null
if (body.slug != null) {
if (body.slug) {
if (typeof body.slug !== 'string') return FloraicResponses.INVALID_REQUEST;
slug = encodeURI(body.slug)
}
Expand Down

0 comments on commit 660e5ac

Please sign in to comment.