merged branch cordoval/bugfix/7644 (PR #7655)

This PR was squashed before being merged into the 2.2 branch (closes #7655).

Discussion
----------

[Config] #7644 add tests for passing number looking attributes as strings

| Q                       | A                 |
| -----------------  |:-------------:|
| Bug fix?            | yes             |
| New feature     | no               |
| BC breaks?     | no               |
| Deprecations?| no               |
| Tests pass?    | yes             |
| Fixed tickets    | #7644        |
| License            | MIT            |

Commits
-------

d98118a [Config] #7644 add tests for passing number looking attributes as strings
This commit is contained in:
Fabien Potencier 2013-04-20 20:42:11 +02:00
commit 64ac4d1679
3 changed files with 12 additions and 4 deletions

View File

@ -117,7 +117,15 @@ class XmlUtilsTest extends \PHPUnit_Framework_TestCase
array(100.0, '1e2'),
array(-120.0, '-1.2E2'),
array(-10100.1, '-10100.1'),
array(-10100.1, '-10,100.1'),
array('-10,100.1', '-10,100.1'),
array('1234 5678 9101 1121 3141', '1234 5678 9101 1121 3141'),
array('1,2,3,4', '1,2,3,4'),
array('11,22,33,44', '11,22,33,44'),
array('11,222,333,4', '11,222,333,4'),
array('1,222,333,444', '1,222,333,444'),
array('11,222,333,444', '11,222,333,444'),
array('111,222,333,444', '111,222,333,444'),
array('1111,2222,3333,4444,5555', '1111,2222,3333,4444,5555'),
array('foo', 'foo'),
);
}

View File

@ -193,8 +193,8 @@ class XmlUtils
return false;
case is_numeric($value):
return '0x' == $value[0].$value[1] ? hexdec($value) : floatval($value);
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $value):
return floatval(str_replace(',', '', $value));
case preg_match('/^(-|\+)?[0-9]+(\.[0-9]+)?$/', $value):
return floatval($value);
default:
return $value;
}

View File

@ -16,7 +16,7 @@
<parameter>on</parameter>
<parameter>off</parameter>
<parameter key="float">1.3</parameter>
<parameter>1,000.3</parameter>
<parameter>1000.3</parameter>
<parameter>a string</parameter>
<parameter type="collection">
<parameter>foo</parameter>