[ 
https://issues.apache.org/jira/browse/TRINIDAD-1537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12733428#action_12733428
 ] 

Cale Scholl commented on TRINIDAD-1537:
---------------------------------------

Currently cannot provide patch due to potential patch conflicts.

Fix is as follows:

trinidad-impl\src\main\javascript\META-INF\adf\jsLibs\NumberFormat.js

TrNumberFormat.prototype.stringToNumber = function(numberString)
{
  // parseFloat("123abc45") returns 123, but 123abc45 is considered an invalid 
number on the server, 
  // so check for a valid number first. Exclude non-numbers and disallow 
exponential notation.
  if (isNaN(numberString) || numberString.indexOf('e') != -1 || 
numberString.indexOf('E') != -1)
  {
    throw new TrParseException("not able to parse number");
  }
  return parseFloat(numberString);
}


TrNumberFormat.prototype.stringToCurrency

  ...
  return (stringToNumber(numberString) * -1);

  ...
  numberString = stringToNumber(numberString);


TrNumberFormat.prototype.stringToPercentage = function(percentString)
{
  var isPercentage = (percentString.indexOf('%') != -1);
  if (!isPercentage)
  {
    throw new TrParseException("not able to parse number");
  }
  
  var numberString = percentString.replace(/\%/g, '');
  return stringToNumber(numberString);
}

> client convertNumber truncates invalid number instead of throwing exception
> ---------------------------------------------------------------------------
>
>                 Key: TRINIDAD-1537
>                 URL: https://issues.apache.org/jira/browse/TRINIDAD-1537
>             Project: MyFaces Trinidad
>          Issue Type: Bug
>            Reporter: Cale Scholl
>
> On the client, 123abc45 is truncated to 123, whereas it should throw an 
> exception; the server throws an exception
> The reason that 123abc45 is truncated to 123 is due to a native js function:
> parseFloat("123abc45") returns 123.
> For currency and percent, the number string is parsed using an instance of
> NumberFormat, which calls parseFloat on the number string.
> However, for the number type, _decimalParse applies some "js magic" before
> calling parseFloat:
>   // OK; it's non-empty.  Now, disallow exponential
>   // notation, and then use some JS magic to exclude
>   // non-numbers
>   if ((numberString.indexOf('e') < 0) &&
>       (numberString.indexOf('E') < 0) &&
>       (((numberString * numberString) == 0) ||
>        ((numberString / numberString) == 1)))
> So if we want to rule out number strings like "123abc45" for currency and
> percent, we simply need to apply the same "js magic" to the parsing functions
> in NumberFormat:
>   TrNumberFormat.prototype.stringToNumber
>   TrNumberFormat.prototype.stringToCurrency
>   TrNumberFormat.prototype.stringToPercentage

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to