svl/source/numbers/zforfind.cxx |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

New commits:
commit 89a3caee73c476133af804d9a0a650e72e711d95
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Mon Jul 5 12:06:27 2021 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Jul 5 13:57:51 2021 +0200

    Resolves: tdf#143165 Date input must match separator, D,M,Y not part of
    
    Change-Id: Iae464fd0fc6c480b9a16ccb2f8eb635812c6eeff
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118408
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 068fc73abdf4..4f5fd03ce6be 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -1263,6 +1263,17 @@ static bool lcl_IsSignedYearSep( const OUString& rStr, 
const OUString& rPat, sal
 }
 
 
+/** Length of separator usually is 1 but theoretically could be anything. */
+static sal_Int32 lcl_getPatternSeparatorLength( const OUString& rPat, 
sal_Int32 nPat )
+{
+    sal_Int32 nSep = nPat;
+    sal_Unicode c;
+    while (nSep < rPat.getLength() && (c = rPat[nSep]) != 'D' && c != 'M' && c 
!= 'Y')
+        ++nSep;
+    return nSep - nPat;
+}
+
+
 bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt )
 {
     if (nAcceptedDatePattern >= -1)
@@ -1383,8 +1394,11 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( 
sal_uInt16 nStartPatternAt )
                 bOk = !IsNum[nNext];
                 if (bOk)
                 {
+                    const sal_Int32 nSepLen = lcl_getPatternSeparatorLength( 
rPat, nPat);
+                    // Non-numeric input must match separator exactly to be
+                    // accepted as such.
                     const sal_Int32 nLen = sStrArray[nNext].getLength();
-                    bOk = (rPat.indexOf( sStrArray[nNext], nPat) == nPat);
+                    bOk = (nLen == nSepLen && rPat.indexOf( sStrArray[nNext], 
nPat) == nPat);
                     if (bOk)
                     {
                         nPat += nLen - 1;
@@ -1503,8 +1517,9 @@ bool ImpSvNumberInputScan::SkipDatePatternSeparator( 
sal_uInt16 nParticle, sal_I
         default:
             if (nNext == nParticle)
             {
+                const sal_Int32 nSepLen = lcl_getPatternSeparatorLength( rPat, 
nPat);
                 const sal_Int32 nLen = sStrArray[nNext].getLength();
-                bool bOk = (rPat.indexOf( sStrArray[nNext], nPat) == nPat);
+                bool bOk = (nLen == nSepLen && rPat.indexOf( sStrArray[nNext], 
nPat) == nPat);
                 if (!bOk)
                 {
                     bOk = lcl_IsSignedYearSep( sStrArray[nNext], rPat, nPat);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to