Skip to content

Commit b133b31

Browse files
author
Jerry Cheung
committed
unescape always to_s. test
1 parent f0d74c4 commit b133b31

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

lib/net/ldap/filter.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -644,18 +644,9 @@ def match(entry)
644644
end
645645

646646
##
647-
# If the argument is a string, converts escaped characters (e.g., "\\28") to unescaped characters.
648-
# If the argument is a number, just return as-is.
649-
# Otherwise, an exception is thrown and the rhs argument is rejected.
650-
# ("(").
647+
# Converts escaped characters (e.g., "\\28") to unescaped characters
651648
def unescape(right)
652-
if defined? right.gsub
653-
right.gsub(/\\([a-fA-F\d]{2})/) { [$1.hex].pack("U") }
654-
elsif right.is_a? Fixnum
655-
right.to_s
656-
else
657-
raise ArgumentError, "Did not know how to convert argument \"#{right}\" into the rhs of an LDAP filter"
658-
end
649+
right.to_s.gsub(/\\([a-fA-F\d]{2})/) { [$1.hex].pack("U") }
659650
end
660651
private :unescape
661652

test/test_filter.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,9 @@ def test_parse_ber_escapes_characters
215215
filter = Net::LDAP::Filter.parse_ber(ber.read_ber(Net::LDAP::AsnSyntax))
216216
assert_equal "(objectclass=#{escaped}*#{escaped}*#{escaped})", filter.to_s
217217
end
218+
219+
def test_unescape_fixnums
220+
filter = Net::LDAP::Filter.eq("objectclass", 3)
221+
assert_equal "\xA3\x10\x04\vobjectclass\x04\x013".b, filter.to_ber
222+
end
218223
end

0 commit comments

Comments
 (0)