summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-07-21 17:49:08 -0400
committerChristopher Speller <crspeller@gmail.com>2015-07-21 18:06:30 -0400
commit73ee387319d59dca073e4cd0c1b9b60b392b137d (patch)
tree5f03802e4beca63ae3b175bab20e50e3afd2d956
parent1c08a33b92f72d77d6c5f1fce916e2cd7c655ff0 (diff)
downloadchat-73ee387319d59dca073e4cd0c1b9b60b392b137d.tar.gz
chat-73ee387319d59dca073e4cd0c1b9b60b392b137d.tar.bz2
chat-73ee387319d59dca073e4cd0c1b9b60b392b137d.zip
Fixing issues with files trasitioning to relative paths
-rw-r--r--api/post.go33
-rw-r--r--api/post_test.go2
-rw-r--r--web/react/components/file_preview.jsx4
3 files changed, 5 insertions, 34 deletions
diff --git a/api/post.go b/api/post.go
index fb9fdd1ef..2d25f7ab0 100644
--- a/api/post.go
+++ b/api/post.go
@@ -160,39 +160,6 @@ func CreatePost(c *Context, post *model.Post, doUpdateLastViewed bool) (*model.P
post.UserId = c.Session.UserId
- if len(post.Filenames) > 0 {
- doRemove := false
- for i := len(post.Filenames) - 1; i >= 0; i-- {
- path := post.Filenames[i]
-
- doRemove = false
- if model.UrlRegex.MatchString(path) {
- continue
- } else if model.PartialUrlRegex.MatchString(path) {
- matches := model.PartialUrlRegex.FindAllStringSubmatch(path, -1)
- if len(matches) == 0 || len(matches[0]) < 5 {
- doRemove = true
- }
-
- channelId := matches[0][2]
- if channelId != post.ChannelId {
- doRemove = true
- }
-
- userId := matches[0][3]
- if userId != post.UserId {
- doRemove = true
- }
- } else {
- doRemove = true
- }
- if doRemove {
- l4g.Error("Bad filename discarded, filename=%v", path)
- post.Filenames = append(post.Filenames[:i], post.Filenames[i+1:]...)
- }
- }
- }
-
var rpost *model.Post
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
return nil, result.Err
diff --git a/api/post_test.go b/api/post_test.go
index 3249ed7fa..0cccc74d3 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -37,7 +37,7 @@ func TestCreatePost(t *testing.T) {
channel2 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
- filenames := []string{"/api/v1/files/get/12345678901234567890123456/12345678901234567890123456/test.png", "/api/v1/files/get/" + channel1.Id + "/" + user1.Id + "/test.png", "www.mattermost.com/fake/url", "junk"}
+ filenames := []string{"/api/v1/files/get/12345678901234567890123456/12345678901234567890123456/test.png", "/api/v1/files/get/" + channel1.Id + "/" + user1.Id + "/test.png"}
post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a", Filenames: filenames}
rpost1, err := Client.CreatePost(post1)
diff --git a/web/react/components/file_preview.jsx b/web/react/components/file_preview.jsx
index 553293d2b..e69607206 100644
--- a/web/react/components/file_preview.jsx
+++ b/web/react/components/file_preview.jsx
@@ -19,6 +19,10 @@ module.exports = React.createClass({
var filenameSplit = filename.split('.');
var ext = filenameSplit[filenameSplit.length-1];
var type = utils.getFileType(ext);
+ // This is a temporary patch to fix issue with old files using absolute paths
+ if (filename.indexOf("/api/v1/files/get") != -1) {
+ filename = filename.split("/api/v1/files/get")[1];
+ }
filename = window.location.origin + "/api/v1/files/get" + filename;
if (type === "image") {