Fixed bug #10861: Eval of double2 doesn't work
authorSteffen Kamper <info@sk-typo3.de>
Wed, 20 May 2009 15:47:00 +0000 (15:47 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Wed, 20 May 2009 15:47:00 +0000 (15:47 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-2@5461 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_tcemain.php
t3lib/jsfunc.evalfield.js

index da67983..46b4e92 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-05-20  Steffen Kamper  <info@sk-typo3.de>
+
+       * Fixed bug #10861: Eval of double2 doesn't work
+
 2009-05-19  Ingo Renner  <ingo@typo3.org>
 
        * Follow up to #8561: Checkboxes and labels are aligned badly if in one line (credits Susanne Moog)
index 27854ba..be36cc0 100755 (executable)
@@ -1996,8 +1996,8 @@ class t3lib_TCEmain       {
         *
         * @param       string          Value to evaluate
         * @param       array           Array of evaluations to traverse.
-        * @param       string          Is-in string
-        * @return      string          Modified $value
+        * @param       string          Is-in string for 'is_in' evaluation
+        * @return      array           Modified $value in key 'value' or empty array
         */
        function checkValue_input_Eval($value,$evalArray,$is_in)        {
                $res = Array();
@@ -2020,16 +2020,19 @@ class t3lib_TCEmain     {
                                        }
                                break;
                                case 'double2':
-                                       $theDec = 0;
-                                       for ($a=strlen($value); $a>0; $a--)     {
-                                               if (substr($value,$a-1,1)=='.' || substr($value,$a-1,1)==',')   {
-                                                       $theDec = substr($value,$a);
-                                                       $value = substr($value,0,$a-1);
-                                                       break;
-                                               }
+                                       $value = preg_replace('/[^0-9,\.-]/', '', $value);
+                                       $negative = substr($value, 0, 1) == '-';
+                                       $value = strtr($value, array(',' => '.', '-' => ''));
+                                       if (strpos($value, '.') === false) {
+                                               $value .= '.0';
+                                       }
+                                       $valueArray = explode('.', $value);
+                                       $dec = array_pop($valueArray);
+                                       $value = join('', $valueArray) . '.' . $dec;
+                                       if ($negative) {
+                                               $value *= -1;
                                        }
-                                       $theDec = ereg_replace('[^0-9]','',$theDec).'00';
-                                       $value = intval(str_replace(' ','',$value)).'.'.substr($theDec,0,2);
+                                       $value = number_format($value, 2, '.', '');
                                break;
                                case 'md5':
                                        if (strlen($value)!=32){$set=false;}
index 2886b47..6a4f969 100755 (executable)
@@ -159,18 +159,21 @@ function evalFunc_getNumChars(value)      {
        return outVal;
 }
 function evalFunc_parseDouble(value)   {
-       var theVal = ''+value;
-       var dec=0;
-       if (!value)     return 0;
-       for (var a=theVal.length; a>0; a--)     {
-               if (theVal.substr(a-1,1)=='.' || theVal.substr(a-1,1)==',')     {
-                       dec = theVal.substr(a);
-                       theVal = theVal.substr(0,a-1);
-                       break;
-               }
+       var theVal = "" + value;
+       theVal = theVal.replace(/[^0-9,\.-]/g, "");
+       var negative = theVal.substring(0, 1) === '-';
+       theVal = theVal.replace(/-/g, "");
+       theVal = theVal.replace(/,/g, ".");
+       if (theVal.indexOf(".") == -1) {
+               theVal += ".0";
+       }
+       var parts = theVal.split(".");
+       var dec = parts.pop();
+       theVal = Number(parts.join("") + "." + dec);
+       if (negative) {
+           theVal *= -1;
        }
-       dec = this.getNumChars(dec)+'00';
-       theVal=this.parseInt(this.noSpace(theVal))+TS.decimalSign+dec.substr(0,2);
+       theVal = theVal.toFixed(2);
 
        return theVal;
 }