Fix issue where custom separator could be the same as a character in the prefix
This commit is contained in:
@@ -20,7 +20,7 @@ describe('upload options', () => {
|
||||
it('takes a usable field separator, and falls back for one that could be part of a field', () => {
|
||||
setConfig({ ipp: { upload: { fieldSeparator: '^' } } })
|
||||
expect(fieldSeparator()).toBe('^')
|
||||
for (const bad of ['', '-', 'a', '.', ' ', '/', 7, null]) {
|
||||
for (const bad of ['', '-', 'a', '.', ' ', '/', '^^', '_', 7, null]) {
|
||||
setConfig({ ipp: { upload: { fieldSeparator: bad } } })
|
||||
expect(fieldSeparator()).toBe(',')
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ describe('uploadFilename', () => {
|
||||
it('uses the configured separator, and removes that one instead', () => {
|
||||
expect(uploadFilename('IMG_0042.jpg', 'ipp_upload_', 'jane-smith', '^')).toBe('ipp_upload_jane-smith^IMG_0042.jpg')
|
||||
expect(uploadFilename('Paris, France^2.jpg', 'ipp_upload_', 'jane-smith', '^')).toBe('ipp_upload_jane-smith^Paris, France2.jpg')
|
||||
expect(uploadFilename('IMG_0042.jpg', 'ipp_upload_', 'jane-smith', '~~')).toBe('ipp_upload_jane-smith~~IMG_0042.jpg')
|
||||
})
|
||||
|
||||
it('stays within 254 characters with the extension intact', () => {
|
||||
@@ -113,14 +112,20 @@ describe('uploaderSlug', () => {
|
||||
|
||||
describe('isUsableSeparator', () => {
|
||||
it('accepts punctuation that sanitize keeps', () => {
|
||||
for (const separator of ['^', ',', '~', '#', '+', '^^', '~,']) expect(isUsableSeparator(separator)).toBe(true)
|
||||
for (const separator of ['^', ',', '~', '#', '+']) expect(isUsableSeparator(separator, 'ipp_upload_')).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects anything that could be part of a name or a filename, or is not a string', () => {
|
||||
for (const separator of ['', 'a', '1', '-', '.', ' ', 'x^', '^ ', '/', ':', '*', '"', '\u0000', 'ñ', '٣']) {
|
||||
expect(isUsableSeparator(separator)).toBe(false)
|
||||
it('rejects more than one character, anything that could be part of a name or a filename, or a non-string', () => {
|
||||
for (const separator of ['', 'a', '1', '-', '.', ' ', 'x^', '^ ', '/', ':', '*', '"', '\u0000', 'ñ', '٣', '^^', '~,', '#!']) {
|
||||
expect(isUsableSeparator(separator, 'ipp_upload_')).toBe(false)
|
||||
}
|
||||
expect(isUsableSeparator(undefined)).toBe(false)
|
||||
expect(isUsableSeparator(1)).toBe(false)
|
||||
expect(isUsableSeparator(undefined, 'ipp_upload_')).toBe(false)
|
||||
expect(isUsableSeparator(1, 'ipp_upload_')).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects a character in the prefix, which would hide the prefix from the stacking check', () => {
|
||||
expect(isUsableSeparator('_', 'ipp_upload_')).toBe(false)
|
||||
expect(isUsableSeparator(',', 'ipp,upload ')).toBe(false)
|
||||
expect(isUsableSeparator('_', 'ipp-upload-')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -202,6 +202,8 @@ describe('main', () => {
|
||||
it('refuses an unknown flag or an unusable separator', async () => {
|
||||
expect(await main(['--aply'])).toBe(2)
|
||||
expect(await main(['--separator', '-'])).toBe(2)
|
||||
expect(await main(['--separator', '_'])).toBe(2)
|
||||
expect(errors[errors.length - 1]).toMatch(/with the prefix "ipp_upload_"/)
|
||||
})
|
||||
|
||||
it('reads the separator from config, and exits 1 on an Immich error', async () => {
|
||||
|
||||
Reference in New Issue
Block a user