-
Notifications
You must be signed in to change notification settings - Fork 103
Regex amount parsing wrong #19
Comments
This is a BC break (even if it's preferable), and we have not nearly enough unit test coverage to explicitly show the breakages. Will need to think on this! |
I was thinking something like this at the top of the function might solve the problem. The OFX spec 2.2, page 91 http://www.ofx.net/downloads/OFX%202.2.pdf states:
Are files breaking the standard format common? |
They rarely conform to specs, sadly! There's lots of edge cases taken into account, hence why we could really do with some more unit tests. |
Note: tests showing this weird behaviour are commented with |
As this is a BC break, I'm going to schedule this for 2.0. |
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
We're seeing the same problem when the amount is formatted as 1.00000, it's converted to 1000 rather than 1. |
Same problem over here. -699 is converted to -6.99, -2000 to -20.00 |
Same problem here i solved with $handle = $this->openFile();
while (($line = fgets($handle)) !== false) {
$line = trim($line);
if (starts_with($line, "<TRNAMT>") && ends_with($line, "00")){
$line.="00";
}
$this->fixed .= $line."\n";
}
$parser = new \OfxParser\Parser();
$ofx = $parser->loadFromString($this->fixed); |
The function createAmountFromStr($amountString) seems to have some bugs with strings that aren't number formatted and have one or more trailing 0s. For example, 750 will parse as 7.5 but 50 parses fine.
Here's a playground link demonstrating the issue. http://tehplayground.com/#SSeFA3M80
Thanks
The text was updated successfully, but these errors were encountered: