mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-25 20:26:36 +00:00
Fix image containing dots in the filename considered unsupported (#468)
Currently, we detect the extensions of an image path by finding the first dot, and splitting everything afterwards, however this will fail with image paths containing dots, like `foo.1.2.3-bar.iso.gz`. Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
parent
5ae5a1915d
commit
f674f3d706
@ -114,10 +114,10 @@ SupportedFormats.service('SupportedFormatsModel', function() {
|
|||||||
// to check every possible extension of an image path,
|
// to check every possible extension of an image path,
|
||||||
// like `.tar.gz`.
|
// like `.tar.gz`.
|
||||||
|
|
||||||
const firstDotIndex = image.indexOf('.');
|
const firstDotIndex = _.get(/(\.)[\w\.]+$/.exec(image), 'index');
|
||||||
|
|
||||||
// An image without an extension is not considered a valid image
|
// An image without an extension is not considered a valid image
|
||||||
if (firstDotIndex === -1) {
|
if (!firstDotIndex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,13 @@ describe('Browser: SupportedFormats', function() {
|
|||||||
m.chai.expect(isSupported).to.be.true;
|
m.chai.expect(isSupported).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return true if the extension is supported and the file name includes dots', function() {
|
||||||
|
const supportedExtensions = SupportedFormatsModel.getAllExtensions();
|
||||||
|
const imagePath = '/path/to/foo.1.2.3-bar.' + _.first(supportedExtensions);
|
||||||
|
const isSupported = SupportedFormatsModel.isSupportedImage(imagePath);
|
||||||
|
m.chai.expect(isSupported).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
it('should return true if the extension is a supported one plus a supported compressed extensions', function() {
|
it('should return true if the extension is a supported one plus a supported compressed extensions', function() {
|
||||||
const nonCompressedExtension = _.first(SupportedFormatsModel.getNonCompressedExtensions());
|
const nonCompressedExtension = _.first(SupportedFormatsModel.getNonCompressedExtensions());
|
||||||
const compressedExtension = _.first(SupportedFormatsModel.getCompressedExtensions());
|
const compressedExtension = _.first(SupportedFormatsModel.getCompressedExtensions());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user