4 Commits

Author SHA1 Message Date
Adnan Maolood
b0f27c6f74 fs: Prevent invalid directory links
A file with a name like "gemini:example" would previously result in the
following invalid link:

    => gemini:example gemini:example

Fix by prepending a "./" before each filename, so that the resulting
link looks like:

    => ./gemini:example gemini:example
2022-05-07 13:54:56 -04:00
Yujiri
8c0af18617 Fix parsing of list item lines
According to section 5.5.2 of the Gemini specification (v0.16.1), the
space is mandatory.
2022-03-15 11:07:04 -04:00
Adnan Maolood
353416685a doc: Fix Mux documentation 2022-02-16 12:01:55 -05:00
Adnan Maolood
0ceec22705 readme: Update Gemini specification version 2021-12-18 12:51:04 -05:00
4 changed files with 7 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ Package gemini implements the [Gemini protocol](https://gemini.circumlunar.space
in Go. It provides an API similar to that of net/http to facilitate the in Go. It provides an API similar to that of net/http to facilitate the
development of Gemini clients and servers. development of Gemini clients and servers.
Compatible with version v0.14.3 of the Gemini specification. Compatible with version v0.16.0 of the Gemini specification.
## Usage ## Usage

6
doc.go
View File

@@ -30,7 +30,7 @@ Servers should be configured with certificates:
server.GetCertificate = certificates.Get server.GetCertificate = certificates.Get
Mux is a Gemini request multiplexer. Mux is a Gemini request multiplexer.
Mux can handle requests for multiple hosts and schemes. Mux can handle requests for multiple hosts and paths.
mux := &gemini.Mux{} mux := &gemini.Mux{}
mux.HandleFunc("example.com", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) { mux.HandleFunc("example.com", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
@@ -39,8 +39,8 @@ Mux can handle requests for multiple hosts and schemes.
mux.HandleFunc("example.org/about.gmi", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) { mux.HandleFunc("example.org/about.gmi", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprint(w, "About example.org") fmt.Fprint(w, "About example.org")
}) })
mux.HandleFunc("http://example.net", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) { mux.HandleFunc("/images/", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprint(w, "Proxied content from http://example.net") w.WriteHeader(gemini.StatusGone, "Gone forever")
}) })
server.Handler = mux server.Handler = mux

2
fs.go
View File

@@ -169,7 +169,7 @@ func dirList(w ResponseWriter, f fs.File) {
} }
link := LineLink{ link := LineLink{
Name: name, Name: name,
URL: (&url.URL{Path: name}).EscapedPath(), URL: "./" + url.PathEscape(name),
} }
fmt.Fprintln(w, link.String()) fmt.Fprintln(w, link.String())
} }

View File

@@ -125,8 +125,8 @@ func ParseLines(r io.Reader, handler func(Line)) error {
name = strings.TrimLeft(name, spacetab) name = strings.TrimLeft(name, spacetab)
line = LineLink{url, name} line = LineLink{url, name}
} }
} else if strings.HasPrefix(text, "*") { } else if strings.HasPrefix(text, "* ") {
text = text[1:] text = text[2:]
text = strings.TrimLeft(text, spacetab) text = strings.TrimLeft(text, spacetab)
line = LineListItem(text) line = LineListItem(text)
} else if strings.HasPrefix(text, "###") { } else if strings.HasPrefix(text, "###") {