MCPcopy Create free account
hub / github.com/github/awesome-copilot / validateRelativePath

Function validateRelativePath

eng/external-plugin-validation.mjs:217–247  ·  view source on GitHub ↗
(pathValue, prefix, errors)

Source from the content-addressed store, hash-verified

215}
216
217function validateRelativePath(pathValue, prefix, errors) {
218 if (!isNonEmptyString(pathValue)) {
219 errors.push(`${prefix}: "source.path" must be a non-empty string when provided`);
220 return;
221 }
222
223 if (pathValue === "/") {
224 return;
225 }
226
227 const normalized = path.posix.normalize(pathValue);
228 const segments = pathValue.split("/");
229
230 if (pathValue.startsWith("/") || pathValue.startsWith("../") || normalized !== pathValue || segments.includes("..")) {
231 errors.push(`${prefix}: "source.path" must be a safe relative path inside the repository`);
232 }
233
234 if (pathValue.includes("\\")) {
235 errors.push(`${prefix}: "source.path" must use forward slashes`);
236 }
237
238 if (normalized === ".") {
239 errors.push(`${prefix}: "source.path" must be "/" for the repository root or a plugin root directory relative to the repository root`);
240 }
241
242 if (path.posix.basename(normalized) === "plugin.json") {
243 errors.push(
244 `${prefix}: "source.path" must point to the plugin root directory, not the manifest file; relative to "source.path", expected one of ${formatExpectedPluginRootMessage()}`
245 );
246 }
247}
248
249function validateImmutableRef(ref, prefix, errors) {
250 if (!isNonEmptyString(ref)) {

Callers 1

validateGitHubSourceFunction · 0.85

Calls 2

isNonEmptyStringFunction · 0.85

Tested by

no test coverage detected