From 4a548ac2829f67c5aba00e19976823b2fd7cda65 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 9 Jun 2018 05:50:31 +0200 Subject: [PATCH] Fix #1474 --- app/Import/Converter/Amount.php | 5 +++++ tests/Unit/Import/Converter/AmountTest.php | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/app/Import/Converter/Amount.php b/app/Import/Converter/Amount.php index 21b3769c0c..79a0c218e5 100644 --- a/app/Import/Converter/Amount.php +++ b/app/Import/Converter/Amount.php @@ -109,6 +109,11 @@ class Amount implements ConverterInterface */ private function stripAmount(string $value): string { + if (0 === strpos($value, '--')) { + $value = substr($value, 2); + } + + $str = preg_replace('/[^\-\(\)\.\,0-9 ]/', '', $value); $len = \strlen($str); if ('(' === $str[0] && ')' === $str[$len - 1]) { diff --git a/tests/Unit/Import/Converter/AmountTest.php b/tests/Unit/Import/Converter/AmountTest.php index 40ca358b7a..8211f2539a 100644 --- a/tests/Unit/Import/Converter/AmountTest.php +++ b/tests/Unit/Import/Converter/AmountTest.php @@ -156,6 +156,13 @@ class AmountTest extends TestCase '(33.52)' => '-33.52', '€(63.12)' => '-63.12', '($182.77)' => '-182.77', + + // double minus because why the hell not + '--0.03881677' => '0.03881677', + '--0.33' => '0.33', + '--$1.23' => '1.23', + '--63 5212.4440' => '635212.444', + '--,2' => '0.2', ]; foreach ($values as $value => $expected) { $converter = new Amount;