Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/126115

Change subject: Avoid file names with double spaces
......................................................................

Avoid file names with double spaces

This seems to be causing various issues...
Bug: 62241

Change-Id: I138c4795477faf7c5381ea0e6514f56f89c6372e
---
M javascripts/modules/uploads/PhotoApi.js
M tests/javascripts/modules/uploads/test_PhotoApi.js
2 files changed, 11 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/15/126115/1

diff --git a/javascripts/modules/uploads/PhotoApi.js 
b/javascripts/modules/uploads/PhotoApi.js
index e04c09e..bbfcbad 100644
--- a/javascripts/modules/uploads/PhotoApi.js
+++ b/javascripts/modules/uploads/PhotoApi.js
@@ -63,6 +63,9 @@
                fileSuffix = fileSuffix || '.jpg';
                date = date || new Date();
                name = description.replace( 
/[\x1B\n\x7f\.\[#<>\[\]\|\{\}\/:]/g, '-' );
+               // remove double spaces (bug 62241)
+               // also trim it in case it ends with a double space
+               name = $.trim( name ).replace( /  /g, ' ' );
                // 
https://commons.wikimedia.org/wiki/MediaWiki:Titleblacklist-custom-double-apostrophe
                name = name.replace( /''/g, '\'_' );
 
diff --git a/tests/javascripts/modules/uploads/test_PhotoApi.js 
b/tests/javascripts/modules/uploads/test_PhotoApi.js
index 072738c..2fb55a2 100644
--- a/tests/javascripts/modules/uploads/test_PhotoApi.js
+++ b/tests/javascripts/modules/uploads/test_PhotoApi.js
@@ -153,6 +153,14 @@
                        'Check file name is description with appended date and 
numbers were padded' );
        } );
 
+       QUnit.test( 'generateFileName double spaces', 1, function() {
+               var longDescription = 'double space  woop woop  ',
+                       date = new Date( 2013, 2, 1, 12, 51 ), name;
+
+               name = photo.generateFileName( longDescription, '.jpg', date );
+               strictEqual( name, 'double space woop woop 2013-03-01 
12-51.jpg' );
+       } );
+
        QUnit.test( 'generateFileName long line', 2, function() {
                var i,
                        longDescription = '',

-- 
To view, visit https://gerrit.wikimedia.org/r/126115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I138c4795477faf7c5381ea0e6514f56f89c6372e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to