5824: Fix up support for PDH in vhostname.
[arvados.git] / services / keep-web / handler.go
index 30b4b64850571ec3ca456f208f2ac24ba4d60683..657c72debdd2b615a03a281ed3f6593bb41af0e4 100644 (file)
@@ -28,7 +28,8 @@ func init() {
        anonymousTokens = []string{}
 }
 
-// return s if s is a UUID or a PDH, otherwise ""
+// return a UUID or PDH if s begins with a UUID or URL-encoded PDH;
+// otherwise return "".
 func parseCollectionIdFromDNSName(s string) string {
        // Strip domain.
        if i := strings.IndexRune(s, '.'); i >= 0 {
@@ -40,10 +41,13 @@ func parseCollectionIdFromDNSName(s string) string {
        if i := strings.Index(s, "--"); i >= 0 {
                s = s[:i]
        }
-       if !arvadosclient.UUIDMatch(s) && !arvadosclient.PDHMatch(s) {
-               return ""
+       if arvadosclient.UUIDMatch(s) {
+               return s
        }
-       return s
+       if pdh := strings.Replace(s, "-", "+", 1); arvadosclient.PDHMatch(pdh) {
+               return pdh
+       }
+       return ""
 }
 
 func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {