diff options
author | Corey Hulen <corey@hulen.com> | 2016-01-25 10:40:39 -0500 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2016-01-25 10:40:39 -0500 |
commit | 5478ea34e436109ece417c3704a1fa36d3aba4a5 (patch) | |
tree | 5485132ef310c9e4204b917a36598ee78571d428 | |
parent | d20f9f6ae1431cc3cac0b89bbda1f8d85e1f3c45 (diff) | |
parent | 68285cf1a9d5b37e857298a84e863cad6ffcdc7a (diff) | |
download | chat-5478ea34e436109ece417c3704a1fa36d3aba4a5.tar.gz chat-5478ea34e436109ece417c3704a1fa36d3aba4a5.tar.bz2 chat-5478ea34e436109ece417c3704a1fa36d3aba4a5.zip |
Merge pull request #1977 from hmhealey/plt1685
PLT-1685 Fixed handling of files with no extension
-rw-r--r-- | model/file_info.go | 7 | ||||
-rw-r--r-- | model/file_info_test.go | 22 | ||||
-rw-r--r-- | web/react/components/file_info_preview.jsx | 11 |
3 files changed, 32 insertions, 8 deletions
diff --git a/model/file_info.go b/model/file_info.go index 131baff6d..f785042b3 100644 --- a/model/file_info.go +++ b/model/file_info.go @@ -32,6 +32,11 @@ func GetInfoForBytes(filename string, data []byte) (*FileInfo, *AppError) { mimeType = mime.TypeByExtension(extension) } + if extension != "" && extension[0] == '.' { + // the client expects a file extension without the leading period + extension = extension[1:] + } + hasPreviewImage := isImage if mimeType == "image/gif" { // just show the gif itself instead of a preview image for animated gifs @@ -45,7 +50,7 @@ func GetInfoForBytes(filename string, data []byte) (*FileInfo, *AppError) { return &FileInfo{ Filename: filename, Size: size, - Extension: extension[1:], + Extension: extension, MimeType: mimeType, HasPreviewImage: hasPreviewImage, }, nil diff --git a/model/file_info_test.go b/model/file_info_test.go index ecf0d509c..e89681626 100644 --- a/model/file_info_test.go +++ b/model/file_info_test.go @@ -19,7 +19,7 @@ func TestGetInfoForBytes(t *testing.T) { } else if info.Size != 1000 { t.Fatalf("Got incorrect size: %v", info.Size) } else if info.Extension != "txt" { - t.Fatalf("Git incorrect file extension: %v", info.Extension) + t.Fatalf("Got incorrect file extension: %v", info.Extension) } else if info.MimeType != "text/plain; charset=utf-8" { t.Fatalf("Got incorrect mime type: %v", info.MimeType) } else if info.HasPreviewImage { @@ -33,7 +33,7 @@ func TestGetInfoForBytes(t *testing.T) { } else if info.Size != 1000 { t.Fatalf("Got incorrect size: %v", info.Size) } else if info.Extension != "png" { - t.Fatalf("Git incorrect file extension: %v", info.Extension) + t.Fatalf("Got incorrect file extension: %v", info.Extension) } else if info.MimeType != "image/png" { t.Fatalf("Got incorrect mime type: %v", info.MimeType) } else if !info.HasPreviewImage { @@ -49,7 +49,7 @@ func TestGetInfoForBytes(t *testing.T) { } else if info.Size != 35 { t.Fatalf("Got incorrect size: %v", info.Size) } else if info.Extension != "gif" { - t.Fatalf("Git incorrect file extension: %v", info.Extension) + t.Fatalf("Got incorrect file extension: %v", info.Extension) } else if info.MimeType != "image/gif" { t.Fatalf("Got incorrect mime type: %v", info.MimeType) } else if !info.HasPreviewImage { @@ -67,10 +67,24 @@ func TestGetInfoForBytes(t *testing.T) { } else if info.Size != 38689 { t.Fatalf("Got incorrect size: %v", info.Size) } else if info.Extension != "gif" { - t.Fatalf("Git incorrect file extension: %v", info.Extension) + t.Fatalf("Got incorrect file extension: %v", info.Extension) } else if info.MimeType != "image/gif" { t.Fatalf("Got incorrect mime type: %v", info.MimeType) } else if info.HasPreviewImage { t.Fatalf("Got HasPreviewImage = true for animated gif") } + + if info, err := GetInfoForBytes("filewithoutextension", fakeFile); err != nil { + t.Fatal(err) + } else if info.Filename != "filewithoutextension" { + t.Fatalf("Got incorrect filename: %v", info.Filename) + } else if info.Size != 1000 { + t.Fatalf("Got incorrect size: %v", info.Size) + } else if info.Extension != "" { + t.Fatalf("Got incorrect file extension: %v", info.Extension) + } else if info.MimeType != "" { + t.Fatalf("Got incorrect mime type: %v", info.MimeType) + } else if info.HasPreviewImage { + t.Fatalf("Got HasPreviewImage = true for non-image file") + } } diff --git a/web/react/components/file_info_preview.jsx b/web/react/components/file_info_preview.jsx index 4b76cd162..45d89007f 100644 --- a/web/react/components/file_info_preview.jsx +++ b/web/react/components/file_info_preview.jsx @@ -5,11 +5,16 @@ import * as Utils from '../utils/utils.jsx'; export default function FileInfoPreview({filename, fileUrl, fileInfo}) { // non-image files include a section providing details about the file - let infoString = 'File type ' + fileInfo.extension.toUpperCase(); - if (fileInfo.size > 0) { - infoString += ', Size ' + Utils.fileSizeToString(fileInfo.size); + const infoParts = []; + + if (fileInfo.extension !== '') { + infoParts.push('File type ' + fileInfo.extension.toUpperCase()); } + infoParts.push('Size ' + Utils.fileSizeToString(fileInfo.size)); + + const infoString = infoParts.join(', '); + const name = decodeURIComponent(Utils.getFileName(filename)); return ( |