From 8d2651b33d6f3f65aaecf1cc8bf78adda47dcbac Mon Sep 17 00:00:00 2001 From: Michael Grafnetter Date: Wed, 4 Mar 2020 23:13:21 +0100 Subject: [PATCH] Improved DN parsing --- Src/DSInternals.Common.Test/DistinguishedNameTester.cs | 7 +++++++ Src/DSInternals.Common/Data/DistinguishedName.cs | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Src/DSInternals.Common.Test/DistinguishedNameTester.cs b/Src/DSInternals.Common.Test/DistinguishedNameTester.cs index 631fe3c..647cb9d 100644 --- a/Src/DSInternals.Common.Test/DistinguishedNameTester.cs +++ b/Src/DSInternals.Common.Test/DistinguishedNameTester.cs @@ -289,5 +289,12 @@ var dn = new DistinguishedName("OU=Employees,OU=Marketing,DC=adatum,DC=com"); Assert.AreEqual("DC=adatum,DC=com", dn.RootNamingContext.ToString()); } + + [TestMethod] + public void DistinguishedName_RootNamingContext_Vector3() + { + var dn = new DistinguishedName("DC=LON-CL1,cn=MicrosoftDNS,DC=DomainDnsZones,DC=adatum,DC=com"); + Assert.AreEqual("DC=DomainDnsZones,DC=adatum,DC=com", dn.RootNamingContext.ToString()); + } } } diff --git a/Src/DSInternals.Common/Data/DistinguishedName.cs b/Src/DSInternals.Common/Data/DistinguishedName.cs index 5e30336..d1a03e9 100644 --- a/Src/DSInternals.Common/Data/DistinguishedName.cs +++ b/Src/DSInternals.Common/Data/DistinguishedName.cs @@ -96,7 +96,10 @@ { get { - var dcComponents = this.components.Where(component => component.Name.Equals(CommonDirectoryAttributes.DomainComponent, StringComparison.InvariantCultureIgnoreCase)); + var dcComponents = this.components + .Reverse() + .TakeWhile(component => component.Name.Equals(CommonDirectoryAttributes.DomainComponent, StringComparison.InvariantCultureIgnoreCase)) + .Reverse(); var result = new DistinguishedName(); result.components.AddRange(dcComponents); return result;