tbm / test

0 stars 0 forks source link

textutils.replace_numbers() does not replace integers #86

Closed tbm closed 8 years ago

tbm commented 9 years ago

Original report by Zhuoyun Wei (Bitbucket: wzyboy, GitHub: wzyboy).


I use bean-web foo.beancount --incognito to do some public demo. However, some of the numbers in my stock shares are not hidden. It turns out that --incognito calls textutils.replace_numbers() to replace numbers with Xs, while the regular expression used in this function (\b([0-9,]+\.[0-9]*)\b([^0-9,.]|$)) does not substitute numbers that without decimal dots.

tbm commented 8 years ago

Original comment by Martin Blais (Bitbucket: blais, GitHub: blais).


Fixed #86: --incognito mode would not replace away integers without a fractional digit.

tbm commented 8 years ago

Original comment by Zhuoyun Wei (Bitbucket: wzyboy, GitHub: wzyboy).


Hmm... I applied the changeset and tried again. The regex now replaces all numbers with a unit following it, i.e. "100.00 USD", but numbers without a unit are not processed, i.e. "100.00".

Thus, all "operating_currency"s are not getting replaced...

tbm commented 8 years ago

Original comment by Martin Blais (Bitbucket: blais, GitHub: blais).


I'm using a weak heuristic, only replacing numbers followed by some whitespace. Because the replacement is carried out on the entire text, I have to be careful to avoid messing up URLs, this is why I do this (yes, it's a bit of a kludge).

I think I see where the problem is: in the tree renderings. Let me see what I can do, I should probably have an automated test to verify this.

tbm commented 8 years ago

Original comment by Martin Blais (Bitbucket: blais, GitHub: blais).


Pull and try again, I improved the heuristic a bit: https://bitbucket.org/blais/beancount/commits/22d5b39c4bc0a9d0940e7c97f5245c062bb43170

It's still not great, I will add a unit test to ensure there are no numbers anywhere.

tbm commented 8 years ago

Original comment by Zhuoyun Wei (Bitbucket: wzyboy, GitHub: wzyboy).


It works! Now incognito mode hides all numbers, and it does not break URLs.