mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-24 16:14:01 +08:00
fix(downloads): Replace path.sep when saving files - Sentry 8749
This commit is contained in:
parent
1de3a47077
commit
f3464c7db3
2 changed files with 8 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
fs = require 'fs'
|
fs = require 'fs'
|
||||||
|
path = require 'path'
|
||||||
{shell} = require 'electron'
|
{shell} = require 'electron'
|
||||||
NylasAPI = require '../../src/flux/nylas-api'
|
NylasAPI = require '../../src/flux/nylas-api'
|
||||||
File = require '../../src/flux/models/file'
|
File = require '../../src/flux/models/file'
|
||||||
|
@ -67,6 +68,10 @@ describe "FileDownloadStore", ->
|
||||||
expect(FileDownloadStore.pathForFile(f1)).toBe("/Users/testuser/.nylas/downloads/id1/123.png")
|
expect(FileDownloadStore.pathForFile(f1)).toBe("/Users/testuser/.nylas/downloads/id1/123.png")
|
||||||
expect(FileDownloadStore.pathForFile(f2)).toBe("/Users/testuser/.nylas/downloads/id2/123.png")
|
expect(FileDownloadStore.pathForFile(f2)).toBe("/Users/testuser/.nylas/downloads/id2/123.png")
|
||||||
|
|
||||||
|
it "should escape the displayName if it contains path separator characters", ->
|
||||||
|
f1 = new File(filename: "static#{path.sep}b#{path.sep}a.jpg", contentType: 'image/png', id: 'id1')
|
||||||
|
expect(FileDownloadStore.pathForFile(f1)).toBe("/Users/testuser/.nylas/downloads/id1/static-b-a.jpg")
|
||||||
|
|
||||||
describe "_checkForDownloadedFile", ->
|
describe "_checkForDownloadedFile", ->
|
||||||
it "should return true if the file exists at the path and is the right size", ->
|
it "should return true if the file exists at the path and is the right size", ->
|
||||||
f = new File(filename: '123.png', contentType: 'image/png', id: "id", size: 100)
|
f = new File(filename: '123.png', contentType: 'image/png', id: "id", size: 100)
|
||||||
|
|
|
@ -126,7 +126,9 @@ FileDownloadStore = Reflux.createStore
|
||||||
#
|
#
|
||||||
pathForFile: (file) ->
|
pathForFile: (file) ->
|
||||||
return undefined unless file
|
return undefined unless file
|
||||||
path.join(@_downloadDirectory, file.id, file.displayName())
|
|
||||||
|
filesafeName = file.displayName().replace(new RegExp(path.sep, 'g'), '-')
|
||||||
|
path.join(@_downloadDirectory, file.id, filesafeName)
|
||||||
|
|
||||||
downloadDataForFile: (fileId) ->
|
downloadDataForFile: (fileId) ->
|
||||||
@_downloads[fileId]?.data()
|
@_downloads[fileId]?.data()
|
||||||
|
|
Loading…
Reference in a new issue