diff --git a/src/helper/ssg/utils.test.ts b/src/helper/ssg/utils.test.ts index 1f3b6b09e..ed151ce63 100644 --- a/src/helper/ssg/utils.test.ts +++ b/src/helper/ssg/utils.test.ts @@ -18,6 +18,8 @@ describe('joinPath', () => { expect(joinPaths('test', '...', 'test2')).toBe('test/.../test2') // single triple dot and single expect(joinPaths('test', './test2', '.test3.')).toBe('test/test2/.test3.') // single and single with slash and single with dot expect(joinPaths('test', '../', '.test2')).toBe('.test2') // single and parent and single with dot + expect(joinPaths('..', '..', 'test')).toBe('../../test') // parent and parent and single + expect(joinPaths('..', '..')).toBe('../..') // parent and parent expect(joinPaths('.test../test2/../')).toBe('.test..') //shuffle expect(joinPaths('.test./.test2/../')).toBe('.test.') //shuffle2 }) diff --git a/src/helper/ssg/utils.ts b/src/helper/ssg/utils.ts index 227204b26..56289dfdc 100644 --- a/src/helper/ssg/utils.ts +++ b/src/helper/ssg/utils.ts @@ -17,8 +17,8 @@ const normalizePath = (path: string): string => { return path.replace(/(\\)/g, '/').replace(/\/$/g, '') } -const handleDotDot = (resultPaths: string[]): void => { - if (resultPaths.length === 0) { +const handleParent = (resultPaths: string[], beforeParentFlag: boolean): void => { + if (resultPaths.length === 0 || beforeParentFlag) { resultPaths.push('..') } else { resultPaths.pop() @@ -33,13 +33,16 @@ const handleNonDot = (path: string, resultPaths: string[]): void => { } const handleSegments = (paths: string[], resultPaths: string[]): void => { + let beforeParentFlag = false for (const path of paths) { - // Handle `..` or `../` + // Handle `..` if (path === '..') { - handleDotDot(resultPaths) + handleParent(resultPaths, beforeParentFlag) + beforeParentFlag = true } else { - // Handle `.` or `./` + // Handle `.` or `abc` handleNonDot(path, resultPaths) + beforeParentFlag = false } } }