MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / getExtraFilepath

Method getExtraFilepath

lib/base-compiler.ts:3171–3185  ·  view source on GitHub ↗
(dirPath: string, filename: string)

Source from the content-addressed store, hash-verified

3169 }
3170
3171 protected getExtraFilepath(dirPath: string, filename: string) {
3172 // note: it's vitally important that the resulting path does not escape dirPath
3173 // (filename is user input and thus unsafe)
3174
3175 const joined = path.join(dirPath, filename);
3176 const normalized = path.normalize(joined);
3177 if (process.platform === 'win32') {
3178 if (!normalized.replaceAll('\\', '/').startsWith(dirPath.replaceAll('\\', '/'))) {
3179 throw new Error('Invalid filename');
3180 }
3181 } else {
3182 if (!normalized.startsWith(dirPath)) throw new Error('Invalid filename');
3183 }
3184 return normalized;
3185 }
3186
3187 fixFiltersBeforeCacheKey(filters: ParseFiltersAndOutputOptions, options: string[], files: FiledataPair[]) {
3188 // Don't run binary for unsupported compilers, even if we're asked.

Callers 3

writeMultipleFilesMethod · 0.95
writeMultipleFilesMethod · 0.80

Calls 1

replaceAllMethod · 0.80

Tested by

no test coverage detected