-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add String()
methods to DN
and its subtypes
#104
Conversation
First, thanks for the PR. A nice way to print is great. I am a little concerned these will be used to serialize DNs for inclusion in filters or actual queries, and they don't escape any values or special characters. |
@liggitt I'd be glad to add escaping of the attribute type and value strings. Is there an existing escape function I can use? |
My intent here is for the |
it's essentially the reverse of what ParseDN does, though that is not straightforward :-/ |
So far the only thing that I'm not sure about is that when an attribute value is originally parsed from BER-encoded data, I don't know whether or not to re-encode it in the same way. An example from an existing test is:
|
I'm also not sure if the existing |
This patch adds `String() string` methods to each of the following types: - DN - RelativeDN - AttributeTypeAndValue So that a `*DN` implements the `fmt.Stringer` interface. These methods also produce normalized strings: Attribute Type and Value are lowercased and joined with a "=" character while multiple attributes of a Relative DN are sorted lexicographically before being joined witha "+" character. This allows one to use the string representation of a DN as a map key and ensure that two DNs which `Equal()` eachother would have the same `String()` value. Docker-DCO-1.1-Signed-off-by: Josh Hawn <[email protected]> (github: jlhawn)
@liggitt I've updated the PR with a function which escapes the attribute value. I've also added an extra case to the
It also asserts the opposite where if one is false then the other must also be false. In order to make this work I had to omit the part which converts the attribute values to be lowercase. I'm still very uncomfortable about that though. |
On the issue of the attribute value equality matching, the original PR which added the
So it doesn't appear to be strictly correct to do exact case matching of the string values. However, if you really want case insensitive matching for the |
Also the CI failures look unrelated - is it the detected race condition which causes the failure? |
@jlhawn does https://github.com/vetinari/go-ldapdn meet your requirements? |
@vetinari almost, yes! The only problem that I see is a bug in the The |
@jlhawn any chance you'd want to update this PR and mirror the changes in both the root folder and the v3 folder? I think we can get this merged in if it's updated. Thanks! |
Was this closed because it was added elsewhere? |
This was closed along with a bunch of other PR's that have been stagnant for a while. If you'd like to shepherd this feature into the code we'd be happy to facilitate that. |
Yeah, it's not something I've touched in a couple years and made my own workaround in the service I built, so likely won't find the TUITs for it anytime soon, but def support the idea. |
@johnweldon I am somewhat interested in getting this code in and might be able to spent some time on it. Though from the looking at the PR history I am not entirely sure what is missing (apart from mirroring stuff to the v3 folder) |
@rhafer - we'd welcome your contributions - as far as I recall it seems it's just the mirroring left. |
This patch adds
String() string
methods to each of the following types:So that a
*DN
implements thefmt.Stringer
interface. These methods alsoproduce normalized strings: Attribute Type and Value are lowercased and joined
with a "=" character while multiple attributes of a Relative DN are sorted
lexicographically before being joined witha "+" character.
This allows one to use the string representation of a DN as a map key and
ensure that two DNs which
Equal()
eachother would have the sameString()
value.