MCPcopy Create free account
hub / github.com/chainreactors/spray / RelaPath

Function RelaPath

pkg/utils.go:322–356  ·  view source on GitHub ↗
(base, u string)

Source from the content-addressed store, hash-verified

320}
321
322func RelaPath(base, u string) string {
323 // 拼接相对目录, 不使用path.join的原因是, 如果存在"////"这样的情况, 可能真的是有意义的路由, 不能随意去掉.
324 // "" /a /a
325 // "" a /a
326 // / "" /
327 // /a/ b /a/b
328 // /a/ /b /a/b
329 // /a b /b
330 // /a /b /b
331
332 if u == "" {
333 return base
334 }
335
336 pathSlash := strings.HasPrefix(u, "/")
337 if base == "" {
338 if pathSlash {
339 return u[1:]
340 } else {
341 return "/" + u
342 }
343 } else if strings.HasSuffix(base, "/") {
344 if pathSlash {
345 return base + u[1:]
346 } else {
347 return base + u
348 }
349 } else {
350 if pathSlash {
351 return Dir(base) + u[1:]
352 } else {
353 return Dir(base) + u
354 }
355 }
356}
357
358func Dir(u string) string {
359 // 安全的获取目录, 不会额外处理多个"//", 并非用来获取上级目录

Callers 1

FormatURLFunction · 0.85

Calls 1

DirFunction · 0.85

Tested by

no test coverage detected