MCPcopy Create free account
hub / github.com/alibaba/open-code-review / WithinBase

Function WithinBase

internal/pathutil/path.go:22–28  ·  view source on GitHub ↗

WithinBase reports whether target is base itself or contained under base.

(base, target string)

Source from the content-addressed store, hash-verified

20
21// WithinBase reports whether target is base itself or contained under base.
22func WithinBase(base, target string) bool {
23 rel, err := filepath.Rel(base, target)
24 if err != nil {
25 return false
26 }
27 return rel == "." || (rel != ".." && !strings.HasPrefix(rel, ".."+string(os.PathSeparator)))
28}

Callers 4

readWorkspaceFileForDiffFunction · 0.92
resolveWorkspacePathMethod · 0.92
TestWithinBaseFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestWithinBaseFunction · 0.68