Skip to content

Commit

Permalink
Merge pull request #15567 from craftcms/bugfix/15565-money-value-can-…
Browse files Browse the repository at this point in the history
…start-with-a-minus

money value can start with a minus
  • Loading branch information
brandonkelly authored Aug 21, 2024
2 parents 0333937 + 7ee2761 commit d2f7190
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fixed a bug where the “Default Values” Table field setting wasn’t escaping column headings. ([#15552](https://github.com/craftcms/cms/issues/15552))
- Fixed a bug where Craft couldn’t be installed with existing project config files, if any plugins specified their schema version via `composer.json`. ([#15559](https://github.com/craftcms/cms/issues/15559))
- Fixed a bug where Money fields’ min, max, and default values weren’t being set to the correct currency. ([#15565](https://github.com/craftcms/cms/issues/15565), [#15566](https://github.com/craftcms/cms/pull/15566))
- Fixed a bug where Money fields weren’t handling negative values correctly. ([#15565](https://github.com/craftcms/cms/issues/15565), [#15567](https://github.com/craftcms/cms/pull/15567))
- Fixed a bug where admin tables weren’t displaying disabled statuses. ([#15540](https://github.com/craftcms/cms/pull/15540))
- Fixed a JavaScript error that occurred when adding a row to an editable table that didn’t allow reordering rows. ([#15543](https://github.com/craftcms/cms/issues/15543))
- Fixed an error that occurred when editing an element with a Link field previously set to a URL value, if the field no longer allows URLs. ([#15542](https://github.com/craftcms/cms/issues/15542))
Expand Down
6 changes: 3 additions & 3 deletions src/fields/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed
}

// Fail-safe if the value is not in the correct format
// Try to normalize the value if there are any non-numeric characters
if (is_string($value) && !preg_match('/^\d+$/', $value)) {
// Try to normalize the value if there are any non-numeric characters (except minus sign at the start)
if (is_string($value) && !preg_match('/^(-?)\d+$/', $value)) {
try {
$value = MoneyHelper::normalizeString($value);
$value = MoneyHelper::normalizeString($value, new Currency($this->currency));
} catch (ParserException) {
// Catch a parse and return appropriately
if (isset($this->defaultValue) && $this->isFresh($element)) {
Expand Down

0 comments on commit d2f7190

Please sign in to comment.