diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2014-12-30 21:48:21 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-01-23 20:32:52 +0000 |
commit | b7d02d7a5a374da3e01e0abc4022fba35daa1840 (patch) | |
tree | 268e534e109ab5676230ece46132c11387a92b89 | |
parent | 0efbd9931ea854cf71c4c54ca3f3d55d6db1fa13 (diff) |
Resolves fdo#87834: strange behavior of mid()-function
See https://bugs.freedesktop.org/show_bug.cgi?id=87834
Thank you Michael Büssow for pointing these cases
Change-Id: I3a9b58360ddab529d1fb2f7eeba7f1c7ae69ba7c
Reviewed-on: https://gerrit.libreoffice.org/13707
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | basic/source/runtime/methods.cxx | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 281781550d32..d3928a599662 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -1205,7 +1205,7 @@ RTLFUNC(Mid) } OUString aArgStr = rPar.Get(1)->GetOUString(); sal_Int32 nStartPos = rPar.Get(2)->GetLong(); - if ( nStartPos == 0 ) + if ( nStartPos < 1 ) { StarBASIC::Error( SbERR_BAD_ARGUMENT ); } @@ -1279,12 +1279,18 @@ RTLFUNC(Mid) else { OUString aResultStr; - if(nLen < 0) + if (nStartPos > aArgStr.getLength()) + { + aResultStr = ""; + } + else if(nArgCount == 2) { aResultStr = aArgStr.copy( nStartPos); } else { + if (nLen < 0) + nLen = 0; if(nStartPos + nLen > aArgStr.getLength()) { nLen = aArgStr.getLength() - nStartPos; |