@@ -707,43 +707,18 @@ protected function getErrorMessage(string $rule, string $field, string $label =
707707 */
708708 protected function splitRules (string $ rules ): array
709709 {
710- $ _rules = [];
711- $ pipe_pos = strpos ($ rules , '| ' );
712- while ($ pipe_pos !== false )
713- {
714- // the if is for the regex_match
715- // if the pattern contains | (pipe) the split was incorrect
716- // so we make sure that, if the pipe is in a pattern we find the separator and
717- // grab the string up to the separator + closing bracket
718- $ open_bracket_pos = strpos ($ rules , '[ ' );
719- if ($ open_bracket_pos !== false && $ open_bracket_pos < $ pipe_pos )
720- {
721- $ separator = $ rules [$ open_bracket_pos +1 ];
722-
723- if (preg_match ('/(?<! \\\\)(?: \\\\\\\\)* \\' .$ separator .'\]/ ' , $ rules , $ matches , PREG_OFFSET_CAPTURE ))
724- {
725- $ regex_end_pos = $ matches [0 ][1 ];
726-
727- $ _rules [] = substr ($ rules , 0 , $ regex_end_pos +2 );
728-
729- $ rules = substr ($ rules , $ regex_end_pos +3 );
730-
731- $ pipe_pos = strpos ($ rules , '| ' );
732- continue ;
733- }
734- }
735-
736- $ _rules [] = substr ($ rules , 0 , $ pipe_pos );
737- $ rules = substr ($ rules , $ pipe_pos +1 );
738-
739- $ pipe_pos = strpos ($ rules , '| ' );
740- }
741-
742- // if there is another rule remaining but no separator just add it to the list
743- if (! empty ($ rules ))
744- {
745- $ _rules [] = $ rules ;
746- }
710+ $ non_escape_bracket = '((?<! \\\\)(?: \\\\\\\\)*[\[\]]) ' ;
711+ $ pipe_not_in_bracket = sprintf (
712+ '/\|(?=(?:[^\[\]]*%s[^\[\]]*%s)*(?![^\[\]]*%s))/ ' ,
713+ $ non_escape_bracket ,
714+ $ non_escape_bracket ,
715+ $ non_escape_bracket
716+ );
717+
718+ $ _rules = preg_split (
719+ $ pipe_not_in_bracket ,
720+ $ rules
721+ );
747722
748723 return array_unique ($ _rules );
749724 }
0 commit comments