Ticket #2528651 (checkedin defect)
Reportermatt marston |
Opened: 11/23/09 Last modified: 11/24/09 Status: checkedin Type: defect Resolution: fixed |
Owner Luke Smith |
Target Release: 2.NEXT Priority: P3 (normal) |
|---|---|---|---|
| Summary: | Function YAHOO.util.Number.format does not return empty string on null input | ||
| Description: | The documentation states that YAHOO.util.Number.format should return an empty string ("") for null, undefined, NaN, or empty string input. In 2.7.0 this worked as documented. In 2.8.0 null and empty |
||
| Type: | defect | Observed in Version: | 2.8.0 |
| Component: | DataSource | Severity: | S3 (normal) |
| Assigned To: | Luke Smith | Target Release: | 2.NEXT |
| Location: | Library Code | Priority: | P3 (normal) |
| Tags: | Relates To: | #2527771 | |
| Browsers: | All | ||
| URL: | |||
| Test Information: |
|
||
Change History
|
Posted: 11/24/09
|
|
Posted: 11/24/09
assigning to Luke for review |
|
Posted: 11/24/09
Another change in Number.format behavior is that the negative now comes before the prefix. I didn't file this as a bug because the documentation doesn't state the expected behavior.
In 2.7.0 this returned $-1,231.18 but in 2.8.0 it now returns -$1,231.18 |
|
Posted: 11/24/09
Another change in Number.format behavior is that a non-numeric string now returns an empty string rather than NaN. I view this as a positive change in behavior.
In 2.7.0 this returned NaN but in 2.8.0 it now returns "" |
|
Posted: 11/24/09
When I wrote the original version of the function as a proof of concept, it always returned a number. When that poc replaced the 2.7 version, it was tweaked to behave similarly. I didn't match up the docs completely, it seems. In light of its support to return empty string for invalids, I agree that null and empty string should (still) return empty string. In previous versions, there was no ability to format negative numbers. You're correct I broke backward compatibility with the feature enhancement. Thanks for catching that. |
|
Posted: 11/24/09
I've corrected the empty string/null => 0 issue. It will now return the empty string for these values as well. To address the back compat issue related to the negativeFormat, I've expanded that feature with an additional config 'format' that acts as a string template for the output. negativeFormat also supports this. This also obviates prefix and suffix, which have been marked as deprecated. Example:
By default, negativeFormat is the same as format, prefixed by - (per the current behavior). So
I added all the tests you provided as well as a few extras for the format/negativeFormat feature enhancement. You can find the new version on GitHub if you'd like. |
|
Posted: 11/24/09
Added format property support to config object for templating rather than fixed prefix and suffix properties. Expanded negativeFormat to also use this template system so $-123.45 is allowed again (back compat regression). null and empty string return empty string again (regression). [fixes #2528651]. Added tests for bug fix verification and for format/negativeFormat coverage. Other misc formatting fixes. |


}
was replaced by a check that performs implicit conversion to a number, which converts null and "" to 0