milesj / uploader

[Deprecated] A CakePHP plugin for file uploading and validating.
MIT License
193 stars 73 forks source link

Get a Warning: invalid range in character class #176

Closed FrodeMMeling closed 10 years ago

FrodeMMeling commented 10 years ago

When uploading I get this error:

Warning (2): preg_replace() [function.preg-replace]: Compilation failed: invalid range in character class at offset 5 [APP/Vendor/mjohnson/transit/src/Transit/File.php, line 413]

Is this a known problem? File is uploaded and moved to correct folder, but filename is empty causing image column to only get .jpg as name.

milesj commented 10 years ago

What version of Transit are you using? What's the name of the file being uploaded?

FrodeMMeling commented 10 years ago

installed from composer:

  mjohnson/admin                1.3.2              A CakePHP admin plugin.
  mjohnson/decoda               6.4.3              A lightweight lexical string parser for BBCode styled markup.
  mjohnson/transit              1.5.0              A file uploader with support for validation, image transformation and remote transportation.
  mjohnson/uploader             4.5.2              File uploader and validation plugin for CakePHP.
  mjohnson/utility              1.6.6              A collection of CakePHP utility libraries.

I added a formatName and dumped the $name and $file array:

/Model/FileUpload.php (line 24)
'IMG_3167'
/Model/FileUpload.php (line 25)
object(Transit\File) {
    [protected] _cache => array()
    [protected] _data => array(
        'name' => 'IMG_3167.jpg',
        'type' => 'image/jpeg',
        'tmp_name' => '/Users/username/dev/apps/myapp/tmp/IMG_3167.jpg',
        'error' => (int) 0,
        'size' => (int) 1882907
    )
    [protected] _path => '/Users/username/dev/apps/myapp/filestore/assetFiles/IMG_3167.jpg'
}

file is stored into assetFiles folder, but as .jpg

milesj commented 10 years ago

What PHP version are you using? I wonder if you have an outdated PCRE: http://www.php.net/manual/en/pcre.installation.php

Or you don't have unicode enabled. http://www.php.net/manual/en/regexp.reference.unicode.php

Would need to install php with --enable-unicode-properties. I wonder if I can check for this.

FrodeMMeling commented 10 years ago

I have PHP 5.5.10. I do not think PCRE can be turned off in this version. (from:php.net As of PHP 5.3.0 this extension cannot be disabled and is therefore always present.) cake version 2.4.6.

from php -i :

echo PCRE_VERSION; = 8.34 2013-12-1
milesj commented 10 years ago

Must be not compiled with unicode properties. Let me see if thats easy to figure out.

FrodeMMeling commented 10 years ago

I have a regular setup om OSX using homebrew and josegonzalez/homebrew-php

milesj commented 10 years ago

Can you run this in terminal pcretest -C? I'm curious if it's related to the PHP PCRE.

FrodeMMeling commented 10 years ago
PCRE version 8.34 2013-12-15
Compiled with
  8-bit support
  UTF-8 support
  16-bit support
  UTF-16 support
  32-bit support
  UTF-32 support
  Unicode properties support
  Just-in-time compiler support: x86 64bit (little endian + unaligned)
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Parentheses nest limit = 250
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack
milesj commented 10 years ago

Probably not a unicode issue then. I'm curious, can you test something for me?

On the regex line: https://github.com/milesj/transit/blob/master/src/Transit/File.php#L413

Try escaping the - and see if that fixes it.

FrodeMMeling commented 10 years ago

Yep. Now it works:

       $name = preg_replace('/[^_\-\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/imu', '-', $name);
milesj commented 10 years ago

Weird. I wonder why no one else has ran into the problem before (might be a 5.5 issue). Easy fix though.

milesj commented 10 years ago

Updated Transit. https://github.com/milesj/transit/commit/7a70dfdb69ea5b7db959dc5a202d9acba4ff3fb7