cmd/golink: short names must begin with word char

also move special "system" URLs like /_/export and /_/base to /.export
and /.base, respectively.

Change-Id: Ica2b11ce3f97575c2755ae1516dd4bc6d814ece4
This commit is contained in:
Will Norris
2022-06-14 16:22:07 -07:00
parent 0e1d350bb9
commit 0a93d9a715
3 changed files with 6 additions and 5 deletions
+4 -3
View File
@@ -88,8 +88,9 @@ func main() {
go flushStatsLoop()
http.HandleFunc("/", serveGo)
http.HandleFunc("/_/export", serveExport)
http.Handle("/_/static/", http.StripPrefix("/_/", http.FileServer(http.FS(embeddedFS))))
http.HandleFunc("/.export", serveExport)
http.Handle("/_/export", http.RedirectHandler("/.export", http.StatusMovedPermanently))
http.Handle("/.static/", http.StripPrefix("/.", http.FileServer(http.FS(embeddedFS))))
if *dev != "" {
log.Printf("Running in dev mode on %s ...", *dev)
@@ -338,7 +339,7 @@ func userExists(ctx context.Context, login string) (bool, error) {
return false, nil
}
var reShortName = regexp.MustCompile(`^[\w\-\.]+$`)
var reShortName = regexp.MustCompile(`^\w[\w\-\.]*$`)
// serveSave handles requests to save or update a Link. Both short name and
// long URL are validated for proper format. Existing links may only be updated
+1 -1
View File
@@ -1,7 +1,7 @@
<html>
<head>
<title>go/</title>
<link rel="stylesheet" href="/_/static/base.css">
<link rel="stylesheet" href="/.static/base.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="flex flex-col min-h-screen">
+1 -1
View File
@@ -3,4 +3,4 @@
set -e
set -x
curl -o $(dirname "$0")/link-snapshot.json 'http://go/_/export?clicks=false'
curl -o $(dirname "$0")/link-snapshot.json 'http://go/.export?clicks=false'