2021-02-23 22:52:26 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
const should = require('should/as-function')
|
|
|
|
const url = require('../../src/model/url')
|
|
|
|
|
|
|
|
describe('URLs', () => {
|
|
|
|
it('escapes non-URL-friendly characters', () => {
|
|
|
|
const chars = {
|
|
|
|
'%': '%25',
|
|
|
|
'#': '%23',
|
|
|
|
'?': '%3F'
|
|
|
|
}
|
|
|
|
_.each(chars, (encoded, character) => {
|
|
|
|
const res = url.fromPath(`photos/image${character}.jpg`)
|
|
|
|
should(res).eql(`photos/image${encoded}.jpg`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-03-03 22:19:36 +00:00
|
|
|
itLinux('converts standard Linux paths', function () {
|
|
|
|
const res = url.fromPath('photos/holidays/IMG_001.jpg')
|
|
|
|
should(res).eql('photos/holidays/IMG_001.jpg')
|
2021-02-23 22:52:26 +00:00
|
|
|
})
|
|
|
|
|
2021-03-03 22:19:36 +00:00
|
|
|
itLinux('encodes backslash in Linux paths', function () {
|
|
|
|
const res = url.fromPath('photos/my\\holidays.jpg')
|
|
|
|
should(res).eql('photos/my%5Cholidays.jpg')
|
|
|
|
})
|
2021-02-23 22:52:26 +00:00
|
|
|
|
2021-03-03 22:19:36 +00:00
|
|
|
itWindows('converts standard Windows paths', function () {
|
|
|
|
const res = url.fromPath('photos\\holidays\\IMG_001.jpg')
|
|
|
|
should(res).eql('photos/holidays/IMG_001.jpg')
|
|
|
|
})
|
2021-02-23 22:52:26 +00:00
|
|
|
|
2021-03-03 22:19:36 +00:00
|
|
|
itWindows('slashes are also valid path separators on Windows', function () {
|
|
|
|
const res = url.fromPath('photos/holidays/IMG_001.jpg')
|
|
|
|
should(res).eql('photos/holidays/IMG_001.jpg')
|
2021-02-23 22:52:26 +00:00
|
|
|
})
|
|
|
|
})
|