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

[BUG]: IncludedMaximum & IncludedMinimum behavior inverted for StringLength, Min, Max validation #16560

Closed
oyeaussie opened this issue Apr 2, 2024 · 2 comments
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Comments

@oyeaussie
Copy link

Expected behavior
The includedMinimum and includedMaximum in stringlength validation, when set to "true", should compare the string length with operators <= & >=, but instead they compare it with < & >

Workaround is to switch them to "false"

Steps to reproduce the behavior:

$data = [];
$data['testMin'] = '12345678';
$data['testMax'] = '12345678901234567890';
$this->validation->add(
    'testMin',
    StringLength::class,
        [
            "min"             => 8,
            "max"             => 20,
            "messageMinimum"  => "minimum length requirement failed.",
            "messageMaximum"  => "maximum length requirement failed.",
            "includedMinimum" => true,
            "includedMaximum" => true
        ]
    );
$this->validation->add(
    'testMax',
    StringLength::class,
        [
            "min"             => 8,
            "max"             => 20,
            "messageMinimum"  => "minimum length requirement failed.",
            "messageMaximum"  => "maximum length requirement failed.",
            "includedMinimum" => true,
            "includedMaximum" => true
        ]
    );

$validated = $this->validation->validate($data)->jsonSerialize();
var_dump($this->validation);die();

object(Validation)[211]
  protected 'validator' => 
    object(Phalcon\Filter\Validation)[390]
      protected 'container' => null
      protected 'combinedFieldsValidators' => 
        array (size=0)
          empty
      protected 'data' => 
        array (size=2)
          'testMin' => string '12345678' (length=8)
          'testMax' => string '12345678901234567890' (length=20)
      protected 'entity' => null
      protected 'filters' => 
        array (size=0)
          empty
      protected 'labels' => 
        array (size=0)
          empty
      protected 'messages' => 
        object(Phalcon\Messages\Messages)[385]
          protected 'position' => int 0
          protected 'messages' => 
            array (size=2)
              0 => 
                object(Phalcon\Messages\Message)[386]
                  protected 'code' => int 0
                  protected 'field' => string 'testMin' (length=7)
                  protected 'message' => string 'minimum length requirement failed.' (length=34)
                  protected 'type' => string 'Phalcon\Filter\Validation\Validator\StringLength\Min' (length=52)
                  protected 'metaData' => 
                    array (size=0)
                      empty
              1 => 
                object(Phalcon\Messages\Message)[389]
                  protected 'code' => int 0
                  protected 'field' => string 'testMax' (length=7)
                  protected 'message' => string 'maximum length requirement failed.' (length=34)
                  protected 'type' => string 'Phalcon\Filter\Validation\Validator\StringLength\Max' (length=52)
                  protected 'metaData' => 
                    array (size=0)
                      empty
      protected 'validators' => 
        array (size=2)
          'testMin' => 
            array (size=1)
              0 => 
                object(Phalcon\Filter\Validation\Validator\StringLength)[219]
                  protected 'template' => null
                  protected 'templates' => 
                    array (size=0)
                      empty
                  protected 'options' => 
                    array (size=0)
                      empty
                  protected 'validators' => 
                    array (size=2)
                      0 => 
                        object(Phalcon\Filter\Validation\Validator\StringLength\Min)[394]
                          protected 'template' => string 'minimum length requirement failed.' (length=34)
                          protected 'templates' => 
                            array (size=0)
                              empty
                          protected 'options' => 
                            array (size=3)
                              'min' => int 8
                              'message' => string 'minimum length requirement failed.' (length=34)
                              'included' => boolean true
                      1 => 
                        object(Phalcon\Filter\Validation\Validator\StringLength\Max)[410]
                          protected 'template' => string 'maximum length requirement failed.' (length=34)
                          protected 'templates' => 
                            array (size=0)
                              empty
                          protected 'options' => 
                            array (size=3)
                              'max' => int 20
                              'message' => string 'maximum length requirement failed.' (length=34)
                              'included' => boolean true
          'testMax' => 
            array (size=1)
              0 => 
                object(Phalcon\Filter\Validation\Validator\StringLength)[398]
                  protected 'template' => null
                  protected 'templates' => 
                    array (size=0)
                      empty
                  protected 'options' => 
                    array (size=0)
                      empty
                  protected 'validators' => 
                    array (size=2)
                      0 => 
                        object(Phalcon\Filter\Validation\Validator\StringLength\Min)[249]
                          protected 'template' => string 'minimum length requirement failed.' (length=34)
                          protected 'templates' => 
                            array (size=0)
                              empty
                          protected 'options' => 
                            array (size=3)
                              'min' => int 8
                              'message' => string 'minimum length requirement failed.' (length=34)
                              'included' => boolean true
                      1 => 
                        object(Phalcon\Filter\Validation\Validator\StringLength\Max)[392]
                          protected 'template' => string 'maximum length requirement failed.' (length=34)
                          protected 'templates' => 
                            array (size=0)
                              empty
                          protected 'options' => 
                            array (size=3)
                              'max' => int 20
                              'message' => string 'maximum length requirement failed.' (length=34)
                              'included' => boolean true
      protected 'values' => 
        array (size=2)
          'testMin' => string '12345678' (length=8)
          'testMax' => string '12345678901234567890' (length=20)

Details

  • Phalcon version:
    `Phalcon is a full stack PHP framework, delivered as a PHP extension, offering lower resource consumption and high performance.
    phalcon => enabled
    Author => Phalcon Team and contributors
    Version => 5.6.1
    Build Date => Feb 13 2024 18:53:07
    Powered by Zephir => Version 0.18.0-$Id$

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.case_insensitive_column_map => Off => Off
phalcon.orm.cast_last_insert_id_to_int => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.disable_assign_setters => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.exception_on_failed_metadata_save => On => On
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.resultset_prefetch_records => 0 => 0
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.dynamic_update => On => On
phalcon.warning.enable => On => On
`

  • PHP Version:
    PHP 8.3.4 (cli) (built: Mar 16 2024 08:40:08) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.4, Copyright (c) Zend Technologies with Zend OPcache v8.3.4, Copyright (c), by Zend Technologies with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
  • Operating System: Ubuntu 22.04
  • Installation type: installing via package manager
  • Zephir version (if any):NA
  • Server: Apache
  • Other related info (Database, table schema):
@oyeaussie oyeaussie added bug A bug report status: unverified Unverified labels Apr 2, 2024
@niden niden mentioned this issue Apr 4, 2024
5 tasks
@niden niden self-assigned this Apr 4, 2024
@niden niden added status: medium Medium 5.0 The issues we want to solve in the 5.0 release and removed status: unverified Unverified labels Apr 4, 2024
@niden
Copy link
Member

niden commented Apr 4, 2024

Resolved in #16561

Thank you @oyeaussie for reporting this.

@oyeaussie
Copy link
Author

Hello @niden

This doesn't seem like its fixed in version 5.7.x

It seems that your fix was reverted:
https://github.com/phalcon/cphalcon/commits/5.0.x/phalcon/Filter/Validation/Validator/StringLength/Max.zep

Can you please confirm.

Thanks,
Guru.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Status: Implemented
Development

No branches or pull requests

2 participants