aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2014-12-13 10:07:10 +0100
committerMorris Jobke <hey@morrisjobke.de>2014-12-13 10:07:10 +0100
commit5b3971f002abf3a5f94f738eb189567110841574 (patch)
treeaf14ef772230e31ad1c61261654a46df17661688
parent29e1c3a898a66b0b005d230a836a0275e462071c (diff)
parentfdbb68a3c3aa6c6cf6ae5c440dd7b742076f1184 (diff)
downloadnextcloud-server-5b3971f002abf3a5f94f738eb189567110841574.tar.gz
nextcloud-server-5b3971f002abf3a5f94f738eb189567110841574.zip
Merge pull request #12639 from owncloud/bad_mtime_format
Fix formatting of bad dates from external storages
-rw-r--r--apps/files/js/filelist.js19
-rw-r--r--apps/files/tests/js/filelistSpec.js13
-rw-r--r--lib/private/files/storage/common.php2
3 files changed, 30 insertions, 4 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index b20bdf23e1f..b4702ce4f2b 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -649,12 +649,16 @@
icon = OC.Util.replaceSVGIcon(fileData.icon),
name = fileData.name,
type = fileData.type || 'file',
- mtime = parseInt(fileData.mtime, 10) || new Date().getTime(),
+ mtime = parseInt(fileData.mtime, 10),
mime = fileData.mimetype,
path = fileData.path,
linkUrl;
options = options || {};
+ if (isNaN(mtime)) {
+ mtime = new Date().getTime()
+ }
+
if (type === 'dir') {
mime = mime || 'httpd/unix-directory';
}
@@ -771,12 +775,21 @@
if (modifiedColor >= '160') {
modifiedColor = 160;
}
+ var formatted;
+ var text;
+ if (mtime > 0) {
+ formatted = formatDate(mtime);
+ text = OC.Util.relativeModifiedDate(mtime);
+ } else {
+ formatted = t('files', 'Unable to determine date');
+ text = '?';
+ }
td = $('<td></td>').attr({ "class": "date" });
td.append($('<span></span>').attr({
"class": "modified",
- "title": formatDate(mtime),
+ "title": formatted,
"style": 'color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')'
- }).text(OC.Util.relativeModifiedDate(mtime)));
+ }).text(text));
tr.find('.filesize').text(simpleSize);
tr.append(td);
return tr;
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index 83ff532313c..3ca41fbae7d 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -183,6 +183,7 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.find('.nametext').text().trim()).toEqual('testName.txt');
expect($tr.find('.filesize').text()).toEqual('1 kB');
+ expect($tr.find('.date').text()).not.toEqual('?');
expect(fileList.findFileEl('testName.txt')[0]).toEqual($tr[0]);
});
it('generates dir element with correct attributes when calling add() with dir data', function() {
@@ -209,6 +210,7 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.attr('data-mtime')).toEqual('123456');
expect($tr.find('.filesize').text()).toEqual('1 kB');
+ expect($tr.find('.date').text()).not.toEqual('?');
expect(fileList.findFileEl('testFolder')[0]).toEqual($tr[0]);
});
@@ -233,6 +235,7 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.attr('data-mtime')).toEqual('123456');
expect($tr.find('.filesize').text()).toEqual('Pending');
+ expect($tr.find('.date').text()).not.toEqual('?');
});
it('generates dir element with default attributes when calling add() with minimal data', function() {
var fileData = {
@@ -254,6 +257,7 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.attr('data-mtime')).toEqual('123456');
expect($tr.find('.filesize').text()).toEqual('Pending');
+ expect($tr.find('.date').text()).not.toEqual('?');
});
it('generates file element with zero size when size is explicitly zero', function() {
var fileData = {
@@ -264,6 +268,15 @@ describe('OCA.Files.FileList tests', function() {
var $tr = fileList.add(fileData);
expect($tr.find('.filesize').text()).toEqual('0 kB');
});
+ it('generates file element with unknown date when mtime invalid', function() {
+ var fileData = {
+ type: 'dir',
+ name: 'testFolder',
+ mtime: -1
+ };
+ var $tr = fileList.add(fileData);
+ expect($tr.find('.date').text()).toEqual('?');
+ });
it('adds new file to the end of the list', function() {
var $tr;
var fileData = {
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index d76c6aa031b..b3eda1165ab 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -132,7 +132,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
public function filemtime($path) {
$stat = $this->stat($path);
- if (isset($stat['mtime'])) {
+ if (isset($stat['mtime']) && $stat['mtime'] > 0) {
return $stat['mtime'];
} else {
return 0;