You are here

public static function ConversionHelper::unescapeDnValue in Lightweight Directory Access Protocol (LDAP) 8.3

Same name and namespace in other branches
  1. 8.4 ldap_servers/src/Helper/ConversionHelper.php \Drupal\ldap_servers\Helper\ConversionHelper::unescapeDnValue()

Undoes the conversion done by escape_dn_value().

Any escape sequence starting with a baskslash - hexpair or special character - will be transformed back to the corresponding character.

Parameters

mixed $values: Array of DN Values.

Return value

array Same as $values, but unescaped

4 calls to ConversionHelper::unescapeDnValue()
LDAPAuthorizationProvider::sanitizeProposals in ldap_authorization/src/Plugin/authorization/Provider/LDAPAuthorizationProvider.php
Sanitize proposals.
Server::getAllRdnValuesFromDn in ldap_servers/src/Entity/Server.php
Returns all RDN values from DN.
Server::getFirstRdnValueFromDn in ldap_servers/src/Entity/Server.php
Return the first RDN Value from DN.
TokenProcessor::ldapTokenizationProcessDnParts in ldap_servers/src/Processor/TokenProcessor.php
Tokenization of DN parts.

File

ldap_servers/src/Helper/ConversionHelper.php, line 185

Class

ConversionHelper
Conversion helper to escape values correctly for LDAP filters.

Namespace

Drupal\ldap_servers\Helper

Code

public static function unescapeDnValue($values) {
  $inputIsScalar = is_scalar($values);

  // Parameter validation.
  if (!is_array($values)) {
    $values = [
      $values,
    ];
  }
  foreach ($values as $key => $val) {

    // Strip slashes from special chars.
    $val = str_replace('\\\\', '\\', $val);
    $val = str_replace('\\,', ',', $val);
    $val = str_replace('\\+', '+', $val);
    $val = str_replace('\\"', '"', $val);
    $val = str_replace('\\<', '<', $val);
    $val = str_replace('\\>', '>', $val);
    $val = str_replace('\\;', ';', $val);
    $val = str_replace('\\#', '#', $val);
    $val = str_replace('\\=', '=', $val);

    // Translate hex code into ascii.
    $values[$key] = self::hex2asc($val);
  }
  if ($inputIsScalar) {
    return $values[0];
  }
  else {
    return $values;
  }
}