Skip to content

Commit

Permalink
Fixed parsing of values with narrow non-breaking spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
voidgraphics committed Dec 31, 2021
1 parent c9bf471 commit a73bb01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct($value)
*/
public function extractValue()
{
$string = str_replace([',', ' '], ['.', ''], $this->original);
$string = str_replace([',', ' ', ''], ['.', '', ''], $this->original);

preg_match('/^[^-\.\d]*(\-?\d+(?:\.\d+)?)[^\d]*$/', $string, $matches);

Expand Down
6 changes: 5 additions & 1 deletion tests/Unit/ParsesMonetaryStringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Unit;

use Brick\Money\Money;
use Whitecube\Price\Price;

it('parses decimal (point) currency values', function() {
Expand Down Expand Up @@ -37,3 +36,8 @@
expect(Price::parse('foo', 'EUR')->__toString())->toBe('EUR 0.00');
expect(Price::parse('bar 6.50', 'EUR')->__toString())->toBe('EUR 6.50');
});

it('parses values with both narrow non-breaking and regular spaces', function() {
expect(Price::parse('1 234,56', 'EUR')->__toString())->toBe('EUR 1234.56');
expect(Price::parse('1 234,56', 'EUR')->__toString())->toBe('EUR 1234.56');
});

0 comments on commit a73bb01

Please sign in to comment.