Changeset 41388
- Timestamp:
- 09/18/2017 11:03:06 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-manager.php
r41376 r41388 489 489 } 490 490 491 if ( ! preg_match( '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',$this->_changeset_uuid ) ) {491 if ( ! wp_is_uuid( $this->_changeset_uuid ) ) { 492 492 $this->wp_die( -1, __( 'Invalid changeset UUID' ) ); 493 493 } -
trunk/src/wp-includes/functions.php
r41380 r41388 5706 5706 5707 5707 /** 5708 * Validates that a UUID is valid. 5709 * 5710 * @since 4.9.0 5711 * 5712 * @param mixed $uuid UUID to check. 5713 * @param int $version Specify which version of UUID to check against. Default is none, to accept any UUID version. Otherwise, only version allowed is `4`. 5714 * @return bool The string is a valid UUID or false on failure. 5715 */ 5716 function wp_is_uuid( $uuid, $version = null ) { 5717 5718 if ( ! is_string( $uuid ) ) { 5719 return false; 5720 } 5721 5722 if ( is_numeric( $version ) ) { 5723 if ( 4 !== (int) $version ) { 5724 _doing_it_wrong( __FUNCTION__, __( 'Only UUID V4 is supported at this time.' ), '4.9.0' ); 5725 return false; 5726 } 5727 $regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/'; 5728 } else { 5729 $regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/'; 5730 } 5731 5732 return (bool) preg_match( $regex, $uuid ); 5733 } 5734 5735 /** 5708 5736 * Get last changed date for the specified cache group. 5709 5737 * -
trunk/tests/phpunit/tests/functions.php
r40564 r41388 902 902 for ( $i = 0; $i < 20; $i += 1 ) { 903 903 $uuid = wp_generate_uuid4(); 904 $this->assert RegExp( '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $uuid);904 $this->assertTrue( wp_is_uuid( $uuid, 4 ) ); 905 905 $uuids[] = $uuid; 906 906 } … … 908 908 $unique_uuids = array_unique( $uuids ); 909 909 $this->assertEquals( $uuids, $unique_uuids ); 910 } 911 912 /** 913 * Tests wp_is_uuid(). 914 * 915 * @covers ::wp_is_uuid 916 * @ticket 39778 917 */ 918 function test_wp_is_valid_uuid() { 919 $uuids_v4 = array( 920 '27fe2421-780c-44c5-b39b-fff753092b55', 921 'b7c7713a-4ee9-45a1-87ed-944a90390fc7', 922 'fbedbe35-7bf5-49cc-a5ac-0343bd94360a', 923 '4c58e67e-123b-4290-a41c-5eeb6970fa3e', 924 'f54f5b78-e414-4637-84a9-a6cdc94a1beb', 925 'd1c533ac-abcf-44b6-9b0e-6477d2c91b09', 926 '7fcd683f-e5fd-454a-a8b9-ed15068830da', 927 '7962c750-e58c-470a-af0d-ec1eae453ff2', 928 'a59878ce-9a67-4493-8ca0-a756b52804b3', 929 '6faa519d-1e13-4415-bd6f-905ae3689d1d', 930 ); 931 932 foreach ( $uuids_v4 as $uuid ) { 933 $this->assertTrue( wp_is_uuid( $uuid, 4 ) ); 934 } 935 936 $uuids = array( 937 '00000000-0000-0000-0000-000000000000', // Nil. 938 '9e3a0460-d72d-11e4-a631-c8e0eb141dab', // Version 1. 939 '2c1d43b8-e6d7-376e-af7f-d4bde997cc3f', // Version 3. 940 '39888f87-fb62-5988-a425-b2ea63f5b81e', // Version 5. 941 ); 942 943 foreach ( $uuids as $uuid ) { 944 $this->assertTrue( wp_is_uuid( $uuid ) ); 945 $this->assertFalse( wp_is_uuid( $uuid, 4 ) ); 946 } 947 948 $invalid_uuids = array( 949 'a19d5192-ea41-41e6-b006', 950 'this-is-not-valid', 951 1234, 952 true, 953 array(), 954 ); 955 956 foreach ( $invalid_uuids as $invalid_uuid ) { 957 $this->assertFalse( wp_is_uuid( $invalid_uuid, 4 ) ); 958 $this->assertFalse( wp_is_uuid( $invalid_uuid ) ); 959 } 910 960 } 911 961
Note: See TracChangeset
for help on using the changeset viewer.