mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-17 23:52:36 +00:00
fix(server): expand Windows reserved name check to include extensions
- Updated sanitizeRepoName to block Windows reserved names (CON, NUL, etc.) even when they have extensions (e.g., CON.txt). - Corrected regex and added unit tests for these edge cases to resolve CI failures on Windows. - Ref: https://github.com/abhigyanpatwari/GitNexus/pull/1305#issuecomment-4407200914
This commit is contained in:
parent
478c7e5712
commit
40ccda1b4a
2 changed files with 6 additions and 1 deletions
|
|
@ -273,7 +273,7 @@ export const sanitizeRepoName = (name: string): string => {
|
|||
// 3. Block path traversal segments and Windows reserved names.
|
||||
// Windows reserved names like CON, PRN, AUX, NUL, COM1-9, LPT1-9 cannot
|
||||
// be used as directory names on Windows even if they have an extension.
|
||||
const reserved = /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i;
|
||||
const reserved = /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\..*)?$/i;
|
||||
if (!sanitized || sanitized === '.' || sanitized === '..' || reserved.test(sanitized)) {
|
||||
return 'unknown';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,6 +190,11 @@ describe('git utilities', () => {
|
|||
expect(sanitizeRepoName('NUL')).toBe('unknown');
|
||||
expect(sanitizeRepoName('COM1')).toBe('unknown');
|
||||
expect(sanitizeRepoName('LPT9')).toBe('unknown');
|
||||
|
||||
// Reserved names with extensions
|
||||
expect(sanitizeRepoName('CON.txt')).toBe('unknown');
|
||||
expect(sanitizeRepoName('NUL.tar.gz')).toBe('unknown');
|
||||
expect(sanitizeRepoName('AUX.local')).toBe('unknown');
|
||||
});
|
||||
|
||||
it('returns unknown for empty or invalid input', () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue