framework icon indicating copy to clipboard operation
framework copied to clipboard

Method explodeExplicitRule working wrong with regex rule

Open du-nong-0070 opened this issue 2 years ago • 3 comments

  • Laravel Version: 9.45.1
  • PHP Version: 8.1.13
  • Database Driver & Version:

Description:

Method explodeExplicitRule works wrong with this rule regex:/^[\d\-]*$/|max:20.

It can not explodes this rule to two patterns like

[
   0 => 'regex:/^[\d\-]*$/',
   1 => 'max:20'
]

I have verified it in Laravel 8 and It has worked perfectly. I saw Laravel 9 had changed explodeExplicitRule which made it wrong. In another rule like required|regex:/^[\d\-]*$/|max:20 or just rotate it like max:20|regex:/^[\d\-]*$/, It works perfectly.

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Validation/ValidationRuleParser.php#L86-L103

https://github.com/laravel/framework/blob/8.x/src/Illuminate/Validation/ValidationRuleParser.php#L84-L93

Steps To Reproduce:

use Laravel validator with rule regex:/^[\d\-]*$/|max:20

du-nong-0070 avatar Jan 05 '23 07:01 du-nong-0070

Ping @stevebauman. Seems to be because of the changes made here? https://github.com/laravel/framework/pull/40941

@du-nong-028 can you confirm that reverting that PR fixes your issue?

driesvints avatar Jan 05 '23 12:01 driesvints

Thanks for the ping @driesvints! Looking into this now.

stevebauman avatar Jan 05 '23 14:01 stevebauman

@driesvints Thank you, I confirm that It's working when I revert that PR https://github.com/laravel/framework/pull/40941 @stevebauman FYI Current

array:1 [▼
  "tel" => array:1 [▶
    0 => "regex:/^[\d\-]*$/|max:20"
  ]
]

When reverting that PR

array:1 [▼
  "tel" => array:2 [▶
    0 => "regex:/^[\d\-]*$/"
    1 => "max:20"
  ]
]

du-nong-0070 avatar Jan 06 '23 00:01 du-nong-0070

Thanks @du-nong-028, I appreciate the detail in your report 🙏 . I've submitted a PR that reverts the changes and restores documented behaviour.

stevebauman avatar Jan 07 '23 17:01 stevebauman