From fbb2477643f4043ef2b5827cd14402b9cdeb7241 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 27 Jul 2015 12:34:36 -0400 Subject: [PATCH 1/4] Allow files without extensions to be uploaded as attachments to posts --- model/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/utils.go b/model/utils.go index 093a54e38c2..4c698be2a4f 100644 --- a/model/utils.go +++ b/model/utils.go @@ -319,6 +319,6 @@ func ClearMentionTags(post string) string { } var UrlRegex = regexp.MustCompile(`^((?:[a-z]+:\/\/)?(?:(?:[a-z0-9\-]+\.)+(?:[a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(?:\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(?:\?[a-z0-9+_~\-\.%=&]*)?)?(?:#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(?:\s+|$)$`) -var PartialUrlRegex = regexp.MustCompile(`/([A-Za-z0-9]{26})/([A-Za-z0-9]{26})/((?:[A-Za-z0-9]{26})?.+\.[A-Za-z0-9]{3,})`) +var PartialUrlRegex = regexp.MustCompile(`/([A-Za-z0-9]{26})/([A-Za-z0-9]{26})/((?:[A-Za-z0-9]{26})?.+(\.[A-Za-z0-9]{3,})?)`) var SplitRunes = map[rune]bool{',': true, ' ': true, '.': true, '!': true, '?': true, ':': true, ';': true, '\n': true, '<': true, '>': true, '(': true, ')': true, '{': true, '}': true, '[': true, ']': true, '+': true, '/': true, '\\': true} From d8e9b7c8e4d9450995855a22005a82541f67a500 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 27 Jul 2015 12:43:40 -0400 Subject: [PATCH 2/4] Allow users to download file attachments with names that don't include a file extension --- api/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/file.go b/api/file.go index 889c9dd1bcb..3ef50fbbd5e 100644 --- a/api/file.go +++ b/api/file.go @@ -33,7 +33,7 @@ func InitFile(r *mux.Router) { sr := r.PathPrefix("/files").Subrouter() sr.Handle("/upload", ApiUserRequired(uploadFile)).Methods("POST") - sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+\\.[A-Za-z0-9]{3,}}", ApiAppHandler(getFile)).Methods("GET") + sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+(\\.[A-Za-z0-9]{3,})?}", ApiAppHandler(getFile)).Methods("GET") sr.Handle("/get_public_link", ApiUserRequired(getPublicLink)).Methods("POST") } From 1842868410ff13b46053f363eb22595faf9d2e7c Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 27 Jul 2015 12:36:14 -0400 Subject: [PATCH 3/4] Display thumbnails for files without file extensions --- web/react/components/post_body.jsx | 2 +- web/react/utils/utils.jsx | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/web/react/components/post_body.jsx b/web/react/components/post_body.jsx index 7871f52b7d3..9f598ecb363 100644 --- a/web/react/components/post_body.jsx +++ b/web/react/components/post_body.jsx @@ -126,7 +126,7 @@ module.exports = React.createClass({ } else if (i < Constants.MAX_DISPLAY_FILES) { postFiles.push(
- +
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 00580af6e39..fbf1e0d4f07 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -546,10 +546,13 @@ module.exports.getIconClassName = function(fileType) { module.exports.splitFileLocation = function(fileLocation) { var fileSplit = fileLocation.split('.'); - if (fileSplit.length < 2) return {}; - var ext = fileSplit[fileSplit.length-1]; - fileSplit.splice(fileSplit.length-1,1) + var ext = ""; + if (fileSplit.length > 1) { + ext = fileSplit[fileSplit.length - 1]; + fileSplit.splice(fileSplit.length - 1, 1); + } + var filePath = fileSplit.join('.'); var filename = filePath.split('/')[filePath.split('/').length-1]; From 892fe2b7b6b801e31dd23d74be14d68c989a4d12 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 28 Jul 2015 10:10:44 -0400 Subject: [PATCH 4/4] Added non-capturing group to regex used for matching local file urls --- model/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/utils.go b/model/utils.go index 4c698be2a4f..c7f991da200 100644 --- a/model/utils.go +++ b/model/utils.go @@ -319,6 +319,6 @@ func ClearMentionTags(post string) string { } var UrlRegex = regexp.MustCompile(`^((?:[a-z]+:\/\/)?(?:(?:[a-z0-9\-]+\.)+(?:[a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(?:\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(?:\?[a-z0-9+_~\-\.%=&]*)?)?(?:#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(?:\s+|$)$`) -var PartialUrlRegex = regexp.MustCompile(`/([A-Za-z0-9]{26})/([A-Za-z0-9]{26})/((?:[A-Za-z0-9]{26})?.+(\.[A-Za-z0-9]{3,})?)`) +var PartialUrlRegex = regexp.MustCompile(`/([A-Za-z0-9]{26})/([A-Za-z0-9]{26})/((?:[A-Za-z0-9]{26})?.+(?:\.[A-Za-z0-9]{3,})?)`) var SplitRunes = map[rune]bool{',': true, ' ': true, '.': true, '!': true, '?': true, ':': true, ';': true, '\n': true, '<': true, '>': true, '(': true, ')': true, '{': true, '}': true, '[': true, ']': true, '+': true, '/': true, '\\': true}