mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 14:00:39 -07:00
fix: use realpath for fs.contains (#867)
* fix: use realpath for fs.contains * chore: reset file mode changes Made-with: Cursor * fix: Windows compat for contains/containsSync and toLiquidAsync arg order Made-with: Cursor
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import * as fs from './fs-impl'
|
||||
import * as path from 'path'
|
||||
import { mkdtempSync, writeFileSync, symlinkSync, rmSync } from 'fs'
|
||||
import { tmpdir } from 'os'
|
||||
|
||||
const { join } = path
|
||||
|
||||
describe('fs-impl', function () {
|
||||
describe('.resolve()', function () {
|
||||
@@ -50,4 +54,36 @@ describe('fs-impl', function () {
|
||||
expect(content).toContain('should read content if exists')
|
||||
})
|
||||
})
|
||||
describe('.contains()', () => {
|
||||
const canSymlink = process.platform !== 'win32'
|
||||
;(canSymlink ? it : it.skip)('should return false when path is a symlink to outside root', async () => {
|
||||
const root = mkdtempSync(join(tmpdir(), 'liquid-contains-'))
|
||||
const outside = join(tmpdir(), `secret-${Date.now()}.liquid`)
|
||||
writeFileSync(outside, 'x')
|
||||
const link = join(root, 'link.liquid')
|
||||
symlinkSync(outside, link)
|
||||
try {
|
||||
expect(await fs.contains(root, link)).toBe(false)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
rmSync(outside, { force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
describe('.containsSync()', () => {
|
||||
const canSymlink = process.platform !== 'win32'
|
||||
;(canSymlink ? it : it.skip)('should return false when path is a symlink to outside root', () => {
|
||||
const root = mkdtempSync(join(tmpdir(), 'liquid-contains-'))
|
||||
const outside = join(tmpdir(), `secret-${Date.now()}.liquid`)
|
||||
writeFileSync(outside, 'x')
|
||||
const link = join(root, 'link.liquid')
|
||||
symlinkSync(outside, link)
|
||||
try {
|
||||
expect(fs.containsSync(root, link)).toBe(false)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
rmSync(outside, { force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user