Skip to content

Commit 4754a94

Browse files
fix image filename length might be too long
1 parent cdbf140 commit 4754a94

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

extension/scripts/Scraper.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ Scraper.prototype = {
6060

6161
var parts = url.split("/");
6262
var filename = parts[parts.length-1];
63-
filename = filename.replace(/\?/g, "%3F");
64-
filename = filename.replace(/=/g, "%3D");
65-
filename = filename.replace(/&/g, "%26");
63+
filename = filename.replace(/\?/g, "");
64+
if(filename.length > 130) {
65+
filename = filename.substr(0, 130);
66+
}
6667
return filename;
6768
},
6869

tests/spec/ScraperSpec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,18 @@ describe("Scraper", function () {
203203
it("should extract filename from image url with query string", function() {
204204

205205
var image = Scraper.prototype.getFileFilename("http://example.com/image.jpg?a=1&b=2");
206-
expect(image).toEqual("image.jpg%3Fa%3D1%26b%3D2");
206+
expect(image).toEqual("image.jpga=1&b=2");
207+
});
208+
209+
it("should shorten image file name to 143 symbols", function() {
210+
211+
// ext4 max is 254
212+
// ntfs max is 256
213+
// ecryptfs 143
214+
// web scraper allows only 130
215+
216+
var image = Scraper.prototype.getFileFilename("http://example.com/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
217+
expect(image).toEqual("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
207218
});
208219

209220
it("should extract filename from image url without http://", function(){

0 commit comments

Comments
 (0)