diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php index 77cbfda..f0566ab 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -69,8 +69,9 @@ protected function ensureIdentifiersLength($identifier) { $this->maxIdentifierLength = $this->connection->query("SHOW max_identifier_length")->fetchField(); if (strlen($identifierName) > $this->maxIdentifierLength) { - $saveIdentifier = 'drupal_' . Crypt::hashBase64($identifierName) . '_' . $args[2]; - } else { + $saveIdentifier = 'drupal_' . $this->hashBase64($identifierName) . '_' . $args[2]; + } + else { $saveIdentifier = $identifierName; } return $saveIdentifier; @@ -731,6 +732,22 @@ public function getComment($table, $column = NULL) { return $this->connection->query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', array('pg_class', $info['table']))->fetchField(); } } + + /** + * Calculates a base-64 encoded, PostgreSQL-safe sha-256 hash per PostgreSQL + * documentation: 4.1. Lexical Structure. + * + * @param $data + * String to be hashed. + * @return string + * A base-64 encoded sha-256 hash, with + and / replaced with _ and any = + * padding characters removed. + */ + protected function hashBase64($data) { + $hash = base64_encode(hash('sha256', $data, TRUE)); + // Modify the hash so it's safe to use in PostgreSQL identifiers. + return strtr($hash, array('+' => '_', '/' => '_', '=' => '')); + } } /** diff --git a/core/lib/Drupal/Core/Database/Schema.php b/core/lib/Drupal/Core/Database/Schema.php index 4b13dfb..6a1b0dd 100644 --- a/core/lib/Drupal/Core/Database/Schema.php +++ b/core/lib/Drupal/Core/Database/Schema.php @@ -251,6 +251,18 @@ protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) { } /** + * Create names for indexes, primary keys and constraints. + * + * This prevents using {} around non-table names like indexes and keys. + */ + function prefixNonTable($table) { + $args = func_get_args(); + $info = $this->getPrefixInfo($table); + $args[0] = $info['table']; + return implode('_', $args); + } + + /** * Build a condition to match a table name against a standard information_schema. * * The information_schema is a SQL standard that provides information about the