regexPathTerminatedWithMarker is similar to pathTerminatedWithMarker but with regex prefix support. Example: 1. Path: "/registry/app1%2Fremote2/artifact/foo/bar/+/summary" Prefix: => "^/registry/([^/]+)/artifact/" Marker: => "/+" MarkerReplacement: => "" ==> "/registry/app1%2Fremote2/artifact/foo%2
( r *http.Request, regexPrefix string, marker string, markerReplacement string, )
| 238 | // ==> "/registry/abc/artifact/foo%2Fbar/summary" |
| 239 | |
| 240 | func regexPathTerminatedWithMarker( |
| 241 | r *http.Request, |
| 242 | regexPrefix string, |
| 243 | marker string, |
| 244 | markerReplacement string, |
| 245 | ) (bool, error) { |
| 246 | prefixPattern := regexp.MustCompile(regexPrefix) |
| 247 | |
| 248 | matches := prefixPattern.FindStringSubmatch(r.URL.Path) |
| 249 | // In case path doesn't start with prefix - nothing to encode |
| 250 | if len(matches) == 0 { |
| 251 | return false, nil |
| 252 | } |
| 253 | |
| 254 | // We only care about the first match as we provide prefix |
| 255 | prefix := matches[0] |
| 256 | |
| 257 | urlPath := r.URL.Path |
| 258 | if r.URL.RawPath != "" { |
| 259 | urlPath = r.URL.RawPath |
| 260 | } |
| 261 | return pathTerminatedWithMarkerAndURL(r, prefix, marker, markerReplacement, urlPath) |
| 262 | } |
| 263 | |
| 264 | // cutOutTerminatedPath cuts out the resource path terminated with the provided marker (path segment suffix). |
| 265 | // e.g. subPath: "/space1/space2/+/authToken", marker: "/+" => "/space1/space2" |
no test coverage detected
searching dependent graphs…