better regexps to match newui and closure urls

Change-Id: I7888cc836705b014fdfe711f397dd3d66c4cf6d9
This commit is contained in:
mpl 2012-12-13 16:58:21 +01:00
parent cd32b0b5b9
commit 36db66cbb7
1 changed files with 4 additions and 7 deletions

View File

@ -41,7 +41,7 @@ var _ = log.Printf
var ( var (
staticFilePattern = regexp.MustCompile(`^([a-zA-Z0-9\-\_]+\.(html|js|css|png|jpg|gif))$`) staticFilePattern = regexp.MustCompile(`^([a-zA-Z0-9\-\_]+\.(html|js|css|png|jpg|gif))$`)
static2FilePattern = regexp.MustCompile(`^(new/)([a-zA-Z0-9\-\_]+\.(html|js|css|png|jpg|gif))$`) static2FilePattern = regexp.MustCompile(`^new/([a-zA-Z0-9\-\_]+\.(html|js|css|png|jpg|gif))$`)
identPattern = regexp.MustCompile(`^[a-zA-Z\_]+$`) identPattern = regexp.MustCompile(`^[a-zA-Z\_]+$`)
// Download URL suffix: // Download URL suffix:
@ -51,7 +51,7 @@ var (
downloadPattern = regexp.MustCompile(`^download/([^/]+)(/.*)?$`) downloadPattern = regexp.MustCompile(`^download/([^/]+)(/.*)?$`)
thumbnailPattern = regexp.MustCompile(`^thumbnail/([^/]+)(/.*)?$`) thumbnailPattern = regexp.MustCompile(`^thumbnail/([^/]+)(/.*)?$`)
treePattern = regexp.MustCompile(`^tree/([^/]+)(/.*)?$`) treePattern = regexp.MustCompile(`^tree/([^/]+)(/.*)?$`)
closurePattern = regexp.MustCompile(`^(new/closure/)([^/]+)(/.*)?$`) closurePattern = regexp.MustCompile(`^new/closure/(([^/]+)(/.*)?)$`)
) )
var uiFiles = uistatic.Files var uiFiles = uistatic.Files
@ -234,15 +234,12 @@ func (ui *UIHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
file := "" file := ""
if m := staticFilePattern.FindStringSubmatch(suffix); m != nil { if m := staticFilePattern.FindStringSubmatch(suffix); m != nil {
file = m[1] file = m[1]
// TODO(mpl): change the regexp to make it not match the stripped part
} else if m := static2FilePattern.FindStringSubmatch(suffix); m != nil { } else if m := static2FilePattern.FindStringSubmatch(suffix); m != nil {
file = strings.Replace(suffix, m[1], "", 1) req.URL.Path = "/" + m[1]
req.URL.Path = "/" + file
ui.newUIStaticHandler.ServeHTTP(rw, req) ui.newUIStaticHandler.ServeHTTP(rw, req)
break break
} else if m := closurePattern.FindStringSubmatch(suffix); m != nil { } else if m := closurePattern.FindStringSubmatch(suffix); m != nil {
file = strings.Replace(suffix, m[1], "", 1) req.URL.Path = "/" + m[1]
req.URL.Path = "/" + file
ui.closureHandler.ServeHTTP(rw, req) ui.closureHandler.ServeHTTP(rw, req)
break break
} else { } else {