From cd840f0828ec597345bad5718d1318a9e0dc623e Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Fri, 30 Aug 2013 23:21:18 -0700 Subject: [PATCH] =?UTF-8?q?Issue=20#2046097=20by=20Berdir,=20G=C3=A1bor=20?= =?UTF-8?q?Hojtsy:=20Fixed=20Very=20long=20URL=20(>255)=20leads=20to=20PDO?= =?UTF-8?q?=20exception=20when=20translation=20source=20locations=20are=20?= =?UTF-8?q?updated.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/Drupal/locale/StringDatabaseStorage.php | 2 ++ .../lib/Drupal/locale/Tests/LocaleStringTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php b/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php index d18e35f0fb41..4860819a0ac1 100644 --- a/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php +++ b/core/modules/locale/lib/Drupal/locale/StringDatabaseStorage.php @@ -146,6 +146,8 @@ protected function updateLocation($string) { $created = FALSE; foreach ($locations as $type => $location) { foreach ($location as $name => $lid) { + // Make sure that the name isn't longer than 255 characters. + $name = substr($name, 0, 255); if (!$lid) { $this->dbDelete('locales_location', array('sid' => $string->getId(), 'type' => $type, 'name' => $name)) ->execute(); diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php index 470164571651..26b8080345f6 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleStringTest.php @@ -105,6 +105,19 @@ function testStringCRUDAPI() { $this->assertFalse($string, 'Successfully deleted source string.'); $deleted = $search = $this->storage->getTranslations(array('lid' => $lid)); $this->assertFalse($deleted, 'Successfully deleted all translation strings.'); + + // Tests that locations of different types and arbitrary lengths can be + // added to a source string. Too long locations will be cut off. + $source_string = $this->buildSourceString(); + $source_string->addLocation('javascript', $this->randomString(8)); + $source_string->addLocation('configuration', $this->randomString(50)); + $source_string->addLocation('code', $this->randomString(100)); + $source_string->addLocation('path', $location = $this->randomString(300)); + $source_string->save(); + + $rows = db_query('SELECT * FROM {locales_location} WHERE sid = :sid', array(':sid' => $source_string->lid))->fetchAllAssoc('type'); + $this->assertEqual(count($rows), 4, '4 source locations have been persisted.'); + $this->assertEqual($rows['path']->name, substr($location, 0, 255), 'Too long location has been limited to 255 characters.'); } /** @@ -166,6 +179,9 @@ function testStringSearchAPI() { /** * Creates random source string object. + * + * @return \Drupal\locale\StringInterface + * A locale string. */ function buildSourceString($values = array()) { return $this->storage->createString($values += array( -- GitLab