Skip to content
This repository has been archived by the owner on Jul 5, 2018. It is now read-only.

Bug 39571: truncate long filenames #195

Merged
merged 1 commit into from Aug 29, 2012
Merged

Conversation

bvibber
Copy link
Contributor

@bvibber bvibber commented Aug 28, 2012

  • strip more evil chars
  • changes filename format to "[truncated filtered name] DD-MM-YY HH-MM-SS.jpg"
  • truncates to fit filenames in 240 UTF-8 bytes, cut in half, with extra wiggle room for thumb stuff

Includes a test case with a super long monument name from Belarus.

var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec' ];
var suffix = d.getDate() + months[ d.getMonth() ] + d.getFullYear() + ' ' + d.getHours() + 'hrs' + d.getMinutes() + 'mins' + d.getSeconds() + 'secs';
return name.replace( /[\x7f\.\[#<>\[\]\|\{\}]/g, '-' ) + ' (taken on ' + suffix + ').jpg';
function pad(str, len) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace

@jdlrobson
Copy link
Member

Looks good but a few bits of refactoring (and please do these as fixups during a rebase) before merging please.

* Adds trimUtf8String function to utils.js, with some test cases.
* strip more evil chars from filenames
* changes filename format to "[truncated filtered name] YYYY-MM-DD HH-MM-SS.jpg"
* truncates to fit filenames in 240 UTF-8 bytes, cut in half, with extra wiggle room for thumb stuff

Includes a test case with a super long monument name from Belarus, and some quick tests for the truncation itself.
@jdlrobson jdlrobson merged commit d1934ba into wikimedia:master Aug 29, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants