fix URL encoding bug

This commit is contained in:
monoid 2023-01-06 22:50:32 +09:00
parent ea4339b2dc
commit 5fc8ba54da
3 changed files with 52 additions and 3 deletions

View File

@ -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<Response> {
}
}
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 {

41
test_data/h#1/SUMMARY.md Normal file
View File

@ -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.

View File

@ -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("/");
}