mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 13:21:37 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -15,83 +15,83 @@ const sinon = require('sinon')
|
||||
const modulePath = '../../../../app/src/Features/Project/SafePath'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('SafePath', function() {
|
||||
beforeEach(function() {
|
||||
describe('SafePath', function () {
|
||||
beforeEach(function () {
|
||||
return (this.SafePath = SandboxedModule.require(modulePath))
|
||||
})
|
||||
|
||||
describe('isCleanFilename', function() {
|
||||
it('should accept a valid filename "main.tex"', function() {
|
||||
describe('isCleanFilename', function () {
|
||||
it('should accept a valid filename "main.tex"', function () {
|
||||
const result = this.SafePath.isCleanFilename('main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not accept an empty filename', function() {
|
||||
it('should not accept an empty filename', function () {
|
||||
const result = this.SafePath.isCleanFilename('')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept / anywhere', function() {
|
||||
it('should not accept / anywhere', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo/bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept .', function() {
|
||||
it('should not accept .', function () {
|
||||
const result = this.SafePath.isCleanFilename('.')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept ..', function() {
|
||||
it('should not accept ..', function () {
|
||||
const result = this.SafePath.isCleanFilename('..')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept * anywhere', function() {
|
||||
it('should not accept * anywhere', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo*bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept leading whitespace', function() {
|
||||
it('should not accept leading whitespace', function () {
|
||||
const result = this.SafePath.isCleanFilename(' foobar.tex')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept trailing whitespace', function() {
|
||||
it('should not accept trailing whitespace', function () {
|
||||
const result = this.SafePath.isCleanFilename('foobar.tex ')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept leading and trailing whitespace', function() {
|
||||
it('should not accept leading and trailing whitespace', function () {
|
||||
const result = this.SafePath.isCleanFilename(' foobar.tex ')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept control characters (0-31)', function() {
|
||||
it('should not accept control characters (0-31)', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\u0010bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept control characters (127, delete)', function() {
|
||||
it('should not accept control characters (127, delete)', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\u007fbar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept control characters (128-159)', function() {
|
||||
it('should not accept control characters (128-159)', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\u0080\u0090bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept surrogate characters (128-159)', function() {
|
||||
it('should not accept surrogate characters (128-159)', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\uD800\uDFFFbar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should accept javascript property names', function() {
|
||||
it('should accept javascript property names', function () {
|
||||
const result = this.SafePath.isCleanFilename('prototype')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should accept javascript property names in the prototype', function() {
|
||||
it('should accept javascript property names in the prototype', function () {
|
||||
const result = this.SafePath.isCleanFilename('hasOwnProperty')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
@@ -105,171 +105,171 @@ describe('SafePath', function() {
|
||||
// result = @SafePath.isCleanFilename 'hello.'
|
||||
// result.should.equal false
|
||||
|
||||
it('should not accept \\', function() {
|
||||
it('should not accept \\', function () {
|
||||
const result = this.SafePath.isCleanFilename('foo\\bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should reject filenames regardless of order (/g) for bad characters', function() {
|
||||
it('should reject filenames regardless of order (/g) for bad characters', function () {
|
||||
const result1 = this.SafePath.isCleanFilename('foo*bar.tex') // * is not allowed
|
||||
const result2 = this.SafePath.isCleanFilename('*foobar.tex') // bad char location is before previous match
|
||||
return result1.should.equal(false) && result2.should.equal(false)
|
||||
})
|
||||
|
||||
it('should reject filenames regardless of order (/g) for bad filenames', function() {
|
||||
it('should reject filenames regardless of order (/g) for bad filenames', function () {
|
||||
const result1 = this.SafePath.isCleanFilename('foo ') // trailing space
|
||||
const result2 = this.SafePath.isCleanFilename(' foobar') // leading space, match location is before previous match
|
||||
return result1.should.equal(false) && result2.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isCleanPath', function() {
|
||||
it('should accept a valid filename "main.tex"', function() {
|
||||
describe('isCleanPath', function () {
|
||||
it('should accept a valid filename "main.tex"', function () {
|
||||
const result = this.SafePath.isCleanPath('main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should accept a valid path "foo/main.tex"', function() {
|
||||
it('should accept a valid path "foo/main.tex"', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should accept empty path elements', function() {
|
||||
it('should accept empty path elements', function () {
|
||||
const result = this.SafePath.isCleanPath('foo//main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not accept an empty filename', function() {
|
||||
it('should not accept an empty filename', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/bar/')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should accept a path that starts with a slash', function() {
|
||||
it('should accept a path that starts with a slash', function () {
|
||||
const result = this.SafePath.isCleanPath('/etc/passwd')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not accept a path that has an asterisk as the 0th element', function() {
|
||||
it('should not accept a path that has an asterisk as the 0th element', function () {
|
||||
const result = this.SafePath.isCleanPath('*/foo/bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that has an asterisk as a middle element', function() {
|
||||
it('should not accept a path that has an asterisk as a middle element', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/*/bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that has an asterisk as the filename', function() {
|
||||
it('should not accept a path that has an asterisk as the filename', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/bar/*')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that contains an asterisk in the 0th element', function() {
|
||||
it('should not accept a path that contains an asterisk in the 0th element', function () {
|
||||
const result = this.SafePath.isCleanPath('f*o/bar/baz')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that contains an asterisk in a middle element', function() {
|
||||
it('should not accept a path that contains an asterisk in a middle element', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/b*r/baz')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a path that contains an asterisk in the filename', function() {
|
||||
it('should not accept a path that contains an asterisk in the filename', function () {
|
||||
const result = this.SafePath.isCleanPath('foo/bar/b*z')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept multiple problematic elements', function() {
|
||||
it('should not accept multiple problematic elements', function () {
|
||||
const result = this.SafePath.isCleanPath('f*o/b*r/b*z')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept a problematic path with an empty element', function() {
|
||||
it('should not accept a problematic path with an empty element', function () {
|
||||
const result = this.SafePath.isCleanPath('foo//*/bar')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept javascript property names', function() {
|
||||
it('should not accept javascript property names', function () {
|
||||
const result = this.SafePath.isCleanPath('prototype')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept javascript property names in the prototype', function() {
|
||||
it('should not accept javascript property names in the prototype', function () {
|
||||
const result = this.SafePath.isCleanPath('hasOwnProperty')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept javascript property names resulting from substitutions', function() {
|
||||
it('should not accept javascript property names resulting from substitutions', function () {
|
||||
const result = this.SafePath.isCleanPath(' proto ')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isAllowedLength', function() {
|
||||
it('should accept a valid path "main.tex"', function() {
|
||||
describe('isAllowedLength', function () {
|
||||
it('should accept a valid path "main.tex"', function () {
|
||||
const result = this.SafePath.isAllowedLength('main.tex')
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not accept an extremely long path', function() {
|
||||
it('should not accept an extremely long path', function () {
|
||||
const longPath = new Array(1000).join('/subdir') + '/main.tex'
|
||||
const result = this.SafePath.isAllowedLength(longPath)
|
||||
return result.should.equal(false)
|
||||
})
|
||||
|
||||
it('should not accept an empty path', function() {
|
||||
it('should not accept an empty path', function () {
|
||||
const result = this.SafePath.isAllowedLength('')
|
||||
return result.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('clean', function() {
|
||||
it('should not modify a valid filename', function() {
|
||||
describe('clean', function () {
|
||||
it('should not modify a valid filename', function () {
|
||||
const result = this.SafePath.clean('main.tex')
|
||||
return result.should.equal('main.tex')
|
||||
})
|
||||
|
||||
it('should replace invalid characters with _', function() {
|
||||
it('should replace invalid characters with _', function () {
|
||||
const result = this.SafePath.clean('foo/bar*/main.tex')
|
||||
return result.should.equal('foo_bar__main.tex')
|
||||
})
|
||||
|
||||
it('should replace "." with "_"', function() {
|
||||
it('should replace "." with "_"', function () {
|
||||
const result = this.SafePath.clean('.')
|
||||
return result.should.equal('_')
|
||||
})
|
||||
|
||||
it('should replace ".." with "__"', function() {
|
||||
it('should replace ".." with "__"', function () {
|
||||
const result = this.SafePath.clean('..')
|
||||
return result.should.equal('__')
|
||||
})
|
||||
|
||||
it('should replace a single trailing space with _', function() {
|
||||
it('should replace a single trailing space with _', function () {
|
||||
const result = this.SafePath.clean('foo ')
|
||||
return result.should.equal('foo_')
|
||||
})
|
||||
|
||||
it('should replace a multiple trailing spaces with ___', function() {
|
||||
it('should replace a multiple trailing spaces with ___', function () {
|
||||
const result = this.SafePath.clean('foo ')
|
||||
return result.should.equal('foo__')
|
||||
})
|
||||
|
||||
it('should replace a single leading space with _', function() {
|
||||
it('should replace a single leading space with _', function () {
|
||||
const result = this.SafePath.clean(' foo')
|
||||
return result.should.equal('_foo')
|
||||
})
|
||||
|
||||
it('should replace a multiple leading spaces with ___', function() {
|
||||
it('should replace a multiple leading spaces with ___', function () {
|
||||
const result = this.SafePath.clean(' foo')
|
||||
return result.should.equal('__foo')
|
||||
})
|
||||
|
||||
it('should prefix javascript property names with @', function() {
|
||||
it('should prefix javascript property names with @', function () {
|
||||
const result = this.SafePath.clean('prototype')
|
||||
return result.should.equal('@prototype')
|
||||
})
|
||||
|
||||
it('should prefix javascript property names in the prototype with @', function() {
|
||||
it('should prefix javascript property names in the prototype with @', function () {
|
||||
const result = this.SafePath.clean('hasOwnProperty')
|
||||
return result.should.equal('@hasOwnProperty')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user