Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phalcon\Validation\Validator\File triggers notice on strtr array to string conversion #12349

Closed
bkwint opened this issue Oct 22, 2016 · 7 comments
Labels
bug A bug report status: medium Medium
Milestone

Comments

@bkwint
Copy link

bkwint commented Oct 22, 2016

Expected and Actual Behavior

While doing a file upload validation with the Phalcon\Validation\Validator\File validator the system triggers an array to string conversion notice when using the option maxResolution. This means that the expected output when an error occurs displays the text Array instead of the actual max resolution.

( ! ) Notice: Array to string conversion in /public/app/modules/backend/controllers/PictureController.php on line 50
Call Stack
#   Time    Memory  Function    Location
1   0.0003  365256  {main}( )   .../index.php:0
2   0.0005  391168  handle ( )  .../index.php:13
3   0.0063  618992  dispatch ( )    .../index.php:13
4   0.0063  619024  _dispatch ( )   .../index.php:13
5   0.0066  630168  callActionMethod ( )    .../index.php:13
6   0.0066  630552  app\modules\backend\controllers\PictureController->addAction( ) .../index.php:13
7   0.0083  721040  validate ( )    .../PictureController.php:50
8   0.0083  721208  validate ( )    .../PictureController.php:50
9   0.0089  726144  strtr ( )   .../PictureController.php:50

/public/app/modules/backend/controllers/PictureController.php:52:
object(Phalcon\Validation\Message\Group)[100]
  protected '_position' => int 0
  protected '_messages' => 
    array (size=1)
      0 => 
        object(Phalcon\Validation\Message)[101]
          protected '_type' => string 'FileMaxResolution' (length=17)
          protected '_message' => string 'File photo must not exceed Array resolution' (length=43)
          protected '_field' => string 'photo' (length=5)
          protected '_code' => int 0
use Phalcon\Validation\Validator\File as FileValidator;

$validation = new Validation();
$validation->add('photo', new FileValidator([
    'maxSize' => '500K',
    'allowedTypes' => [ 'image/jpeg', 'image/png' ],
    'maxResolution' => '800x800'
]));

$validation->validate($_FILES);

Details

Used version of phalcon
Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.0.1
Build Date => Sep 1 2016 18:22:49
Powered by Zephir => Version 0.9.4a-dev-7e304ba18c

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off

PHP version and operating system
PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.2, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

Installation type
installing via package manager

@sergeyklay
Copy link
Contributor

@Jurigag Could you please take a look

@Jurigag
Copy link
Contributor

Jurigag commented Oct 23, 2016

Just to be sure. Validation is Phalcon\Validation right ? Then problem is happening i guess because of changes i made here 1adfdae#diff-7ce9ac330c42f24966594edd3cd39131R70 but i don't see really where i missed type checking.

@Jurigag
Copy link
Contributor

Jurigag commented Oct 23, 2016

Maybe it's here -

replacePairs = [":field": label, ":max": maxResolution];

But it was done in old validator anyway. This is only one place where this can happen.

Will do test and check it.

Yes this is exactly why it happens, will do fast fix.

Jurigag added a commit to Jurigag/cphalcon that referenced this issue Oct 23, 2016
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Oct 23, 2016
@sergeyklay sergeyklay added this to the 3.0.2 milestone Oct 23, 2016
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Oct 23, 2016
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Oct 23, 2016
Jurigag added a commit to Jurigag/cphalcon that referenced this issue Oct 23, 2016
@Jurigag
Copy link
Contributor

Jurigag commented Oct 23, 2016

It should be fixed by #12352. Tests are not possible though because right now mocking php functions in zephir extension not possible.

sergeyklay pushed a commit that referenced this issue Oct 24, 2016
@sergeyklay
Copy link
Contributor

@bkwint
Could you please check 3.0.x branch?

git clone [email protected]:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x

zephir fullclean
zephir build

@bkwint
Copy link
Author

bkwint commented Nov 9, 2016

@sergeyklay the issue seems resolved with the new build. My apologies with the delay in testing the fix.

@sergeyklay
Copy link
Contributor

Thanks

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

4 participants