{"id":"92d4a6080ea7eb1c","repo":"go-redis/redis","slug":"redis-invalid-url-path-s","errorCode":null,"errorMessage":"redis: invalid URL path: %s","messagePattern":"redis: invalid URL path: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"options.go","lineNumber":703,"sourceCode":"\n\to.Username, o.Password = getUserPassword(u)\n\n\th, p := getHostPortWithDefaults(u)\n\to.Addr = net.JoinHostPort(h, p)\n\n\tf := strings.FieldsFunc(u.Path, func(r rune) bool {\n\t\treturn r == '/'\n\t})\n\tswitch len(f) {\n\tcase 0:\n\t\to.DB = 0\n\tcase 1:\n\t\tvar err error\n\t\tif o.DB, err = strconv.Atoi(f[0]); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"redis: invalid database number: %q\", f[0])\n\t\t}\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"redis: invalid URL path: %s\", u.Path)\n\t}\n\n\tif u.Scheme == \"rediss\" {\n\t\to.TLSConfig = &tls.Config{\n\t\t\tServerName: h,\n\t\t\tMinVersion: tls.VersionTLS12,\n\t\t}\n\t}\n\n\treturn setupConnParams(u, o)\n}\n\n// getHostPortWithDefaults is a helper function that splits the url into\n// a host and a port. If the host is missing, it defaults to localhost\n// and if the port is missing, it defaults to 6379.\nfunc getHostPortWithDefaults(u *url.URL) (string, string) {\n\t// u.Hostname and u.Port strip the surrounding brackets from IPv6 literals\n\t// (e.g. \"[::1]\" -> \"::1\") and handle the missing-port case, which","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/options.go#L685-L721","documentation":"Returned by setupTCPConn when the URL path contains more than one slash-delimited segment (e.g. /0/1). Only zero or one DB-number segment is permitted in a redis:// URL path; anything deeper is treated as malformed.","triggerScenarios":"Passing redis://host:6379/0/1, redis://host:6379/a/b, or any URL whose path has multiple segments. Often from appending extra path components meant for an HTTP-style router.","commonSituations":"Building the URL by joining path parts, a load-balancer/proxy that rewrites the path, or accidentally including a trailing segment.","solutions":["Reduce the path to a single DB-number segment: redis://host:6379/0.","Drop the path and pass the DB via ?db=N or Options.DB.","Normalise/validate the URL string before calling ParseURL."],"exampleFix":"// before\nopt, err := redis.ParseURL(\"redis://localhost:6379/0/extra\")\n// after\nopt, err := redis.ParseURL(\"redis://localhost:6379/0\")","handlingStrategy":"validation","validationCode":"func singleSegmentPath(p string) bool {\n    return len(strings.FieldsFunc(p, func(r rune) bool { return r == '/' })) <= 1\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never join extra path components onto a redis:// URL.","Pass DB via ?db=N if you need a clean empty path.","Validate the URL path has at most one segment before ParseURL."],"tags":["config","url","validation"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}