fix file not found with space

This commit is contained in:
Jurgis Sakalauskas
2023-11-03 19:42:25 +02:00
parent 1e8afa5289
commit b43541a34a
+2 -1
View File
@@ -12,6 +12,7 @@ import { configService } from '../config/config.service';
@Injectable() @Injectable()
export class StaticService { export class StaticService {
async provideDirIndex(relPath: string): Promise<Array<FileDto>> { async provideDirIndex(relPath: string): Promise<Array<FileDto>> {
relPath = decodeURI(relPath);
if (relPath.indexOf('..') > -1) { if (relPath.indexOf('..') > -1) {
throw new UnauthorizedException( throw new UnauthorizedException(
'You are not authorized to visit ' + relPath, 'You are not authorized to visit ' + relPath,
@@ -23,7 +24,7 @@ export class StaticService {
const stats: Stats | false = await stat(path).catch(() => false); const stats: Stats | false = await stat(path).catch(() => false);
if (stats === false) { if (stats === false) {
throw new NotFoundException('Path not found: ' + relPath); throw new NotFoundException('Path is is not found: ' + relPath);
} }
if (!stats.isDirectory()) { if (!stats.isDirectory()) {