From b22b93dc760e415960527246062378d5a60a4024 Mon Sep 17 00:00:00 2001
From: Michele Tartara <mtartara@google.com>
Date: Wed, 21 Nov 2012 17:25:53 +0000
Subject: [PATCH] Implement the correct handling of numbers without commas

commaInt now recognizes only the first 3 digits for numbers without commas.

It was erroneously recognizing numbers of any size before the first comma.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 htools/Ganeti/Block/Drbd/Parser.hs | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/htools/Ganeti/Block/Drbd/Parser.hs b/htools/Ganeti/Block/Drbd/Parser.hs
index 4a8564642..5a78858fa 100644
--- a/htools/Ganeti/Block/Drbd/Parser.hs
+++ b/htools/Ganeti/Block/Drbd/Parser.hs
@@ -304,12 +304,16 @@ timeUnitParser :: Parser TimeUnit
 timeUnitParser = second
   where second = A.string "sec" *> pure Second
 
--- | Haskell does not recognises ',' as the separator every 3 digits
--- but DRBD uses it, so we need an ah-hoc parser.
+-- | Haskell does not recognise ',' as the thousands separator every 3
+-- digits but DRBD uses it, so we need an ah-hoc parser.
+-- If a number beginning with more than 3 digits without a comma is
+-- parsed, only the first 3 digits are considered to be valid, the rest
+-- is not consumed, and left for further parsing.
 commaIntParser :: Parser Int
 commaIntParser = do
-  first <- A.decimal
-  allDigits <- commaIntHelper first
+  first <-
+    AC.count 3 A.digit <|> AC.count 2 A.digit <|> AC.count 1 A.digit
+  allDigits <- commaIntHelper (read first)
   pure allDigits
 
 -- | Helper (triplet parser) for the commaIntParser
-- 
GitLab