summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2014-07-02 22:24:52 +0200
committerEike Rathke <erack@redhat.com>2014-07-02 23:51:48 +0200
commit836e504c859a5b67f7ab7ba842785951d41058cd (patch)
tree5efae410c7196206e488c1e8ac22108167df34d9
parent0459e43ae63191ce9846bbcc7fe797fd949e3878 (diff)
resolved fdo#80166 check input against date acceptance pattern plausibility
... to prevent confusion of #.### input with D.M that then later is discarded as invalid date input instead of accepted as valid numeric input. Change-Id: I178e28b7ef3b26d04eecc73e5e5c61ee41f89e32
-rw-r--r--svl/source/numbers/zforfind.cxx31
1 files changed, 30 insertions, 1 deletions
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index d63fd56a72a5..c2946c3776fb 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -1174,6 +1174,8 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt )
}
nDatePatternStart = nStartPatternAt; // remember start particle
+ const sal_Int32 nMonthsInYear = pFormatter->GetCalendar()->getNumberOfMonthsInYear();
+
for (sal_Int32 nPattern=0; nPattern < sDateAcceptancePatterns.getLength(); ++nPattern)
{
sal_uInt16 nNext = nDatePatternStart;
@@ -1183,12 +1185,39 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt )
sal_Int32 nPat = 0;
for ( ; nPat < rPat.getLength() && bOk && nNext < nAnzStrings; ++nPat, ++nNext)
{
- switch (rPat[nPat])
+ const sal_Unicode c = rPat[nPat];
+ switch (c)
{
case 'Y':
case 'M':
case 'D':
bOk = IsNum[nNext];
+ if (bOk && (c == 'M' || c == 'D'))
+ {
+ // Check the D and M cases for plausibility. This also
+ // prevents recognition of date instead of number with a
+ // numeric group input if date separator is identical to
+ // group separator, for example with D.M as a pattern and
+ // #.### as a group.
+ sal_Int32 nMaxLen, nMaxVal;
+ switch (c)
+ {
+ case 'M':
+ nMaxLen = 2;
+ nMaxVal = nMonthsInYear;
+ break;
+ case 'D':
+ nMaxLen = 2;
+ nMaxVal = 31;
+ break;
+ }
+ bOk = (sStrArray[nNext].getLength() <= nMaxLen);
+ if (bOk)
+ {
+ sal_Int32 nNum = sStrArray[nNext].toInt32();
+ bOk = (1 <= nNum && nNum <= nMaxVal);
+ }
+ }
if (bOk)
++nDatePatternNumbers;
break;