Skip to content
Snippets Groups Projects
Commit c88bf78b authored by catch's avatar catch
Browse files

Issue #3442810 by vidorado, gaurav gupta, sandeep sanwale, smustgrave,...

Issue #3442810 by vidorado, gaurav gupta, sandeep sanwale, smustgrave, prudloff: Deprecation in Number::alphadecimalToInt()
parent cce7d977
No related branches found
No related tags found
3 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!10223132456: Fix issue where views instances are emptied before an ajax request is complete
Pipeline #421157 passed with warnings
Pipeline: drupal

#421166

    Pipeline: drupal

    #421159

      ......@@ -92,10 +92,24 @@ public static function intToAlphadecimal($i = 0) {
      * @return int
      * The integer value.
      *
      * @throws \InvalidArgumentException
      * If $string contains invalid characters, throw an exception.
      *
      * @see \Drupal\Component\Utility\Number::intToAlphadecimal
      */
      public static function alphadecimalToInt($string = '00') {
      return (int) base_convert(substr($string, 1), 36, 10);
      // For backwards compatibility, we must accept NULL
      // and the empty string, returning 0,
      // like (int) base_convert(substr($string, 1), 36, 10) always did.
      if ('' === $string || NULL === $string) {
      @trigger_error('Passing NULL or an empty string to ' . __METHOD__ . '() is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. See https://www.drupal.org/node/3494472', E_USER_DEPRECATED);
      return 0;
      }
      $alpha_decimal_substring = substr($string, 1);
      if (!ctype_alnum($alpha_decimal_substring)) {
      throw new \InvalidArgumentException("Invalid characters passed for attempted conversion: $string");
      }
      return (int) base_convert($alpha_decimal_substring, 36, 10);
      }
      }
      ......@@ -115,7 +115,7 @@ public function preSave(EntityStorageInterface $storage) {
      $max = rtrim((string) $max, '/');
      // We need to get the value at the correct depth.
      $parts = explode('.', $max);
      $n = Number::alphadecimalToInt($parts[0]);
      $n = $parts[0] ? Number::alphadecimalToInt($parts[0]) : 0;
      $prefix = '';
      }
      else {
      ......
      ......@@ -5,6 +5,7 @@
      namespace Drupal\Tests\Component\Utility;
      use Drupal\Component\Utility\Number;
      use Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait;
      use PHPUnit\Framework\TestCase;
      /**
      ......@@ -18,6 +19,8 @@
      */
      class NumberTest extends TestCase {
      use ExpectDeprecationTrait;
      /**
      * Tests Number::validStep() without offset.
      *
      ......@@ -157,4 +160,35 @@ public static function providerTestConversions() {
      ];
      }
      /**
      * Tests the alphadecimal conversion function input parameter checking.
      *
      * Number::alphadecimalToInt() must throw an exception
      * when non-alphanumeric characters are passed as input.
      *
      * @covers ::alphadecimalToInt
      */
      public function testAlphadecimalToIntThrowsExceptionWithMalformedStrings(): void {
      $this->expectException(\InvalidArgumentException::class);
      $nonAlphanumericChar = '#';
      Number::alphadecimalToInt($nonAlphanumericChar);
      }
      /**
      * Tests the alphadecimal conversion function keeps backward compatibility.
      *
      * Many tests and code rely on Number::alphadecimalToInt() returning 0
      * for degenerate values '' and NULL. We must ensure they are accepted.
      *
      * @group legacy
      * @covers ::alphadecimalToInt
      */
      public function testAlphadecimalToIntReturnsZeroWithNullAndEmptyString(): void {
      $deprecationMessage = 'Passing NULL or an empty string to Drupal\Component\Utility\Number::alphadecimalToInt() is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. See https://www.drupal.org/node/3494472';
      $this->expectDeprecation($deprecationMessage);
      $this->assertSame(0, Number::alphadecimalToInt(NULL));
      $this->expectDeprecation($deprecationMessage);
      $this->assertSame(0, Number::alphadecimalToInt(''));
      }
      }
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Finish editing this message first!
      Please register or to comment