Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Fix incorrect regex for amount conversion. #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

enobrev
Copy link

@enobrev enobrev commented Dec 28, 2016

The regex in Ofx::createAmountFromStr included a "?" after the "mark"
whether it be decimal or comma. That "?" made it match number strings
regardless of whether they had a "mark" to parse out, and grossly
changed their value.

This made amounts such as 1000 or -1000 convert to 10 or -10. Removing
the conditional after the mark resolved this issue. There are new tests
to show that this resolves the issue without breaking others.

Resolves #19

The regex in Ofx::createAmountFromStr included a "?" after the "mark"
whether it be decimal or comma.  That "?" made it match number strings
regardless of whether they had a "mark" to parse out, and grossly
changed their value.

This made amounts such as 1000 or -1000 convert to 10 or -10.  Removing
the conditional after the mark resolved this issue.  There are new tests
to show that this resolves the issue without breaking others.

Resolves asgrim#19
@@ -37,7 +37,12 @@ public function amountConversionProvider()
'-1.000,00' => ['-1.000,00', -1000.0],
'1' => ['1', 1.0],
'10' => ['10', 10.0],
'100' => ['100', 1.0], // @todo this is weird behaviour, should not really expect this
'100' => ['100', 100.0],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether right or not, this is a BC break, so targeting this for next major.

@asgrim asgrim added the enhancement This adds new functionality or improves existing functionality. label Jan 17, 2017
@asgrim asgrim added this to the 2.0.0 milestone Jan 17, 2017
@asgrim asgrim self-assigned this Jan 17, 2017
@oceanapplications
Copy link
Contributor

I feel that it's fairly unlikely that many of the users are even aware that they are occasionally getting incorrect results. It would be rather difficult for someone to account for this behavior in their implementation of the library too.

Do you have a rough idea of when the next major release will be up?

@asgrim asgrim added the BC break Changes in this PR/issue would result in a BC break label Oct 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
BC break Changes in this PR/issue would result in a BC break enhancement This adds new functionality or improves existing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regex amount parsing wrong
3 participants