From 005573458081886edb8384ad43a2ae23715a1b42 Mon Sep 17 00:00:00 2001 From: Tom Sellers Date: Thu, 16 Feb 2023 12:22:59 -0600 Subject: [PATCH] Retain spaces in RDN values in DNs --- lib/net/ldap/dn.rb | 10 +++++----- test/test_dn.rb | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/net/ldap/dn.rb b/lib/net/ldap/dn.rb index 866efde7..9098cdb9 100644 --- a/lib/net/ldap/dn.rb +++ b/lib/net/ldap/dn.rb @@ -81,7 +81,7 @@ def each_pair value << char when ',' then state = :key - yield key.string.strip, value.string.rstrip + yield key.string.strip, value.string key = StringIO.new value = StringIO.new; else @@ -93,7 +93,7 @@ def each_pair when '\\' then state = :value_normal_escape when ',' then state = :key - yield key.string.strip, value.string.rstrip + yield key.string.strip, value.string key = StringIO.new value = StringIO.new; else value << char @@ -142,7 +142,7 @@ def each_pair when ' ' then state = :value_end when ',' then state = :key - yield key.string.strip, value.string.rstrip + yield key.string.strip, value.string key = StringIO.new value = StringIO.new; else raise Net::LDAP::InvalidDNError, "DN badly formed" @@ -159,7 +159,7 @@ def each_pair when ' ' then state = :value_end when ',' then state = :key - yield key.string.strip, value.string.rstrip + yield key.string.strip, value.string key = StringIO.new value = StringIO.new; else raise Net::LDAP::InvalidDNError, "DN badly formed" @@ -172,7 +172,7 @@ def each_pair raise Net::LDAP::InvalidDNError, "DN badly formed" unless [:value, :value_normal, :value_hexstring, :value_end].include? state - yield key.string.strip, value.string.rstrip + yield key.string.strip, value.string end ## diff --git a/test/test_dn.rb b/test/test_dn.rb index fa2266f7..52e87bd7 100644 --- a/test/test_dn.rb +++ b/test/test_dn.rb @@ -14,6 +14,12 @@ def test_escape_space assert_equal '\\ before_after\\ ', Net::LDAP::DN.escape(' before_after ') end + def test_retain_spaces + dn = Net::LDAP::DN.new('CN=Foo.bar.baz, OU=Foo \ ,OU=\ Bar, O=Baz') + assert_equal "CN=Foo.bar.baz, OU=Foo \\ ,OU=\\ Bar, O=Baz", dn.to_s + assert_equal ["CN", "Foo.bar.baz", "OU", "Foo ", "OU", " Bar", "O", "Baz"], dn.to_a + end + def test_escape_on_initialize dn = Net::LDAP::DN.new('cn', ',+"\\<>;', 'ou=company') assert_equal 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company', dn.to_s @@ -26,7 +32,7 @@ def test_to_a def test_to_a_parenthesis dn = Net::LDAP::DN.new('cn = \ James , ou = "Comp\28ny" ') - assert_equal ['cn', ' James', 'ou', 'Comp(ny'], dn.to_a + assert_equal ['cn', ' James ', 'ou', 'Comp(ny'], dn.to_a end def test_to_a_hash_symbol pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy