Skip to content

Commit

Permalink
Refactor getInts to explicitly set split Limit in preg_split
Browse files Browse the repository at this point in the history
- Set `-1` as the limit in `preg_split` within the `getInts` method to explicitly prevent a split limit,

According to [w3schools documentation](https://www.w3schools.com/php/func_regex_preg_split.asp), `-1` is the default limit. However, this was not working...

Considered using `explode` for simplicity but retained `preg_split` for its whitespace-trimming capability. This ensures consistent handling of branch IDs that may include extra spaces around separators (e.g., "18 , 24").
  • Loading branch information
kasperbirch1 committed Nov 4, 2024
1 parent 5c84e02 commit e7a3c5a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion web/modules/custom/drupal_typed/src/RequestTyped.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getInts(string $key, array $default = [], string $separator = ",
if ($value === NULL) {
return $default;
}
$strings = \Safe\preg_split("/\s*{$separator}\s*/", $value, PREG_SPLIT_NO_EMPTY);
$strings = \Safe\preg_split("/\s*{$separator}\s*/", $value, -1, PREG_SPLIT_NO_EMPTY);
return array_map(fn($value) => intval($value), $strings);
}

Expand Down

0 comments on commit e7a3c5a

Please sign in to comment.