File tree 2 files changed +11
-7
lines changed
2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -175,16 +175,14 @@ public static function isNegative($value)
175
175
* isAddress
176
176
*
177
177
* @param string $value
178
- * @return bool
178
+ * @return bool true if the address is lowercase or in checksum format otherwise false
179
179
*/
180
180
public static function isAddress ($ value )
181
181
{
182
182
if (!is_string ($ value )) {
183
183
throw new InvalidArgumentException ('The value to isAddress function must be string. ' );
184
184
}
185
- if (preg_match ('/^(0x|0X)?[a-f0-9A-F]{40}$/ ' , $ value ) !== 1 ) {
186
- return false ;
187
- } elseif (preg_match ('/^(0x|0X)?[a-f0-9]{40}$/ ' , $ value ) === 1 || preg_match ('/^(0x|0X)?[A-F0-9]{40}$/ ' , $ value ) === 1 ) {
185
+ if (preg_match ('/^(0x)?[a-f0-9]{40}$/ ' , $ value ) === 1 ) {
188
186
return true ;
189
187
}
190
188
return self ::isAddressChecksum ($ value );
@@ -202,6 +200,9 @@ public static function isAddressChecksum($value)
202
200
throw new InvalidArgumentException ('The value to isAddressChecksum function must be string. ' );
203
201
}
204
202
$ value = self ::stripZero ($ value );
203
+ if (mb_strlen ($ value ) !== 40 ) {
204
+ return false ;
205
+ }
205
206
$ hash = self ::stripZero (self ::sha3 (mb_strtolower ($ value )));
206
207
207
208
for ($ i = 0 ; $ i < 40 ; $ i ++) {
Original file line number Diff line number Diff line change @@ -232,17 +232,20 @@ public function testIsAddress()
232
232
$ this ->assertEquals ($ isAddress , true );
233
233
234
234
$ isAddress = Utils::isAddress ('0Xca35b7d915458ef540ade6068dfe2f44e8fa733c ' );
235
- $ this ->assertEquals ($ isAddress , true );
235
+ $ this ->assertEquals ($ isAddress , false );
236
236
237
237
$ isAddress = Utils::isAddress ('0XCA35B7D915458EF540ADE6068DFE2F44E8FA733C ' );
238
- $ this ->assertEquals ($ isAddress , true );
238
+ $ this ->assertEquals ($ isAddress , false );
239
239
240
240
$ isAddress = Utils::isAddress ('0xCA35B7D915458EF540ADE6068DFE2F44E8FA733C ' );
241
- $ this ->assertEquals ($ isAddress , true );
241
+ $ this ->assertEquals ($ isAddress , false );
242
242
243
243
$ isAddress = Utils::isAddress ('0xCA35B7D915458EF540ADE6068DFE2F44E8FA73cc ' );
244
244
$ this ->assertEquals ($ isAddress , false );
245
245
246
+ $ isAddress = Utils::isAddress ('0xCA35b7d915458Ef540ADE6068DfE2F44E8fA73cC ' );
247
+ $ this ->assertEquals ($ isAddress , true );
248
+
246
249
$ this ->expectException (InvalidArgumentException::class);
247
250
$ isAddress = Utils::isAddress (new stdClass );
248
251
}
You can’t perform that action at this time.
0 commit comments