From 5fc8ba54da185da3d27b387bfaf7c95ca84e32f5 Mon Sep 17 00:00:00 2001 From: monoid Date: Fri, 6 Jan 2023 22:50:32 +0900 Subject: [PATCH] fix URL encoding bug --- routes/dir/[...path].tsx | 10 +++++++--- test_data/h#1/SUMMARY.md | 41 ++++++++++++++++++++++++++++++++++++++++ util/util.ts | 4 ++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 test_data/h#1/SUMMARY.md diff --git a/routes/dir/[...path].tsx b/routes/dir/[...path].tsx index bbe0b01..93f4642 100644 --- a/routes/dir/[...path].tsx +++ b/routes/dir/[...path].tsx @@ -1,6 +1,10 @@ import { HandlerContext, Handlers, PageProps } from "$fresh/server.ts"; -import { asset, Head } from "$fresh/runtime.ts"; -import { encodePath, removePrefixFromPathname } from "../../util/util.ts"; +import { Head } from "$fresh/runtime.ts"; +import { + decodePath, + encodePath, + removePrefixFromPathname, +} from "../../util/util.ts"; import { join } from "path/posix.ts"; import DirList, { EntryInfo } from "../../islands/DirList.tsx"; import FileViewer from "../../islands/FileViewer.tsx"; @@ -127,7 +131,7 @@ async function GET(req: Request, ctx: HandlerContext): Promise { } } const url = new URL(req.url); - const path = removePrefixFromPathname(decodeURI(url.pathname), "/dir"); + const path = removePrefixFromPathname(decodePath(url.pathname), "/dir"); if (url.searchParams.has("pretty")) { return await renderPage(req, path, ctx); } else { diff --git a/test_data/h#1/SUMMARY.md b/test_data/h#1/SUMMARY.md new file mode 100644 index 0000000..384d650 --- /dev/null +++ b/test_data/h#1/SUMMARY.md @@ -0,0 +1,41 @@ +--- +title: Q&A +tags: ["Q&A"] +--- + +# Q&A + +## Q1 + +What is the default branch name? + +## A1 + +The default branch name is `master`. You can change it to any name you like. For +example, you can change it to `main` by following the steps below: + +``` +git branch -m master main +git fetch origin +git branch -u origin/main main +git remote set-head origin -a +``` + +## Q2 + +What is the defference between `git branch` and `git branch -a`? + +## A2 + +`git branch` shows only local branches, while `git branch -a` shows both local +and remote branches. + +## Q3 + +Fast-forward merge is not possible. How can I merge the feature branch into the +main branch? + +## A3 + +You can use `--no-ff` option to force a merge commit even if the merge is a +fast-forward. diff --git a/util/util.ts b/util/util.ts index bb58035..c718bda 100644 --- a/util/util.ts +++ b/util/util.ts @@ -16,3 +16,7 @@ export function removePrefixFromPathname( export function encodePath(path: string): string { return path.split("/").map(encodeURIComponent).join("/"); } + +export function decodePath(path: string): string { + return path.split("/").map(decodeURIComponent).join("/"); +}