Skip url parameters when determining file name or extension.
This commit is contained in:
parent
239a4df91c
commit
a24c3bea05
@ -20,11 +20,16 @@ OV.GetFileName = function (filePath)
|
|||||||
if (firstSeparator !== -1) {
|
if (firstSeparator !== -1) {
|
||||||
fileName = filePath.substr (firstSeparator + 1);
|
fileName = filePath.substr (firstSeparator + 1);
|
||||||
}
|
}
|
||||||
|
let firstParamIndex = fileName.indexOf ('?');
|
||||||
|
if (firstParamIndex !== -1) {
|
||||||
|
fileName = fileName.substr (0, firstParamIndex);
|
||||||
|
}
|
||||||
return decodeURI (fileName);
|
return decodeURI (fileName);
|
||||||
};
|
};
|
||||||
|
|
||||||
OV.GetFileExtension = function (fileName)
|
OV.GetFileExtension = function (filePath)
|
||||||
{
|
{
|
||||||
|
let fileName = OV.GetFileName (filePath);
|
||||||
let firstPoint = fileName.lastIndexOf ('.');
|
let firstPoint = fileName.lastIndexOf ('.');
|
||||||
if (firstPoint === -1) {
|
if (firstPoint === -1) {
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
@ -97,5 +97,21 @@ describe ('IO Test', function () {
|
|||||||
let str2 = OV.ArrayBufferToUtf8String (buffer);
|
let str2 = OV.ArrayBufferToUtf8String (buffer);
|
||||||
assert.strictEqual (str, str2);
|
assert.strictEqual (str, str2);
|
||||||
assert.strictEqual (str.length, str2.length);
|
assert.strictEqual (str.length, str2.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it ('File Name', function () {
|
||||||
|
assert.strictEqual (OV.GetFileName ('file.ext'), 'file.ext');
|
||||||
|
assert.strictEqual (OV.GetFileName ('folder1/folder2/file.ext'), 'file.ext');
|
||||||
|
assert.strictEqual (OV.GetFileName ('folder1\\folder2\\file.ext'), 'file.ext');
|
||||||
|
assert.strictEqual (OV.GetFileName ('https://example.com/file.ext'), 'file.ext');
|
||||||
|
assert.strictEqual (OV.GetFileName ('https://example.com/file.ext?param1=param2'), 'file.ext');
|
||||||
|
});
|
||||||
|
|
||||||
|
it ('File Extension', function () {
|
||||||
|
assert.strictEqual (OV.GetFileExtension ('file.ext'), 'ext');
|
||||||
|
assert.strictEqual (OV.GetFileExtension ('folder1/folder2/file.ext'), 'ext');
|
||||||
|
assert.strictEqual (OV.GetFileExtension ('folder1\\folder2\\file.ext'), 'ext');
|
||||||
|
assert.strictEqual (OV.GetFileExtension ('https://example.com/file.ext'), 'ext');
|
||||||
|
assert.strictEqual (OV.GetFileExtension ('https://example.com/file.ext?param1=param2'), 'ext');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user