You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Cale Scholl (JIRA)" <de...@myfaces.apache.org> on 2009/07/21 02:47:14 UTC

[jira] Created: (TRINIDAD-1537) client convertNumber truncates invalid number instead of throwing exception

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.


[jira] Updated: (TRINIDAD-1537) client convertNumber truncates invalid number instead of throwing exception

Posted by "Matthias Weßendorf (JIRA)" <de...@myfaces.apache.org>.
     [ https://issues.apache.org/jira/browse/TRINIDAD-1537?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matthias Weßendorf updated TRINIDAD-1537:
-----------------------------------------

       Resolution: Fixed
    Fix Version/s:  1.2.12-core
         Assignee: Matthias Weßendorf
           Status: Resolved  (was: Patch Available)

> 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
>            Assignee: Matthias Weßendorf
>             Fix For:  1.2.12-core
>
>         Attachments: 1.2.11.4-branch_strictNumberParse.patch, trunk_strictNumberParse.patch
>
>
> 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.


[jira] Commented: (TRINIDAD-1537) client convertNumber truncates invalid number instead of throwing exception

Posted by "Cale Scholl (JIRA)" <de...@myfaces.apache.org>.
    [ 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.


[jira] Updated: (TRINIDAD-1537) client convertNumber truncates invalid number instead of throwing exception

Posted by "Cale Scholl (JIRA)" <de...@myfaces.apache.org>.
     [ https://issues.apache.org/jira/browse/TRINIDAD-1537?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Cale Scholl updated TRINIDAD-1537:
----------------------------------

    Status: Patch Available  (was: Open)

> 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
>         Attachments: 1.2.11.4-branch_strictNumberParse.patch, trunk_strictNumberParse.patch
>
>
> 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.