Skip to content

Commit

Permalink
Remove invalid characters between @ and "AAMVA" for 2000 standard lic…
Browse files Browse the repository at this point in the history
…enses (fix #25)
  • Loading branch information
c0shea committed Jun 4, 2018
1 parent 43204ce commit aebe300
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
49 changes: 49 additions & 0 deletions IdParser.Test/DriversLicenseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2473,5 +2473,54 @@ public void TestLeadingWhitespaceLicense()
Assert.AreEqual("02360-1234", idCard.Address.PostalCodeDisplay);
Assert.AreEqual("Massachusetts", idCard.IssuerIdentificationNumber.GetDescription());
}

[TestMethod]
public void TestInvalidHeader()
{
var expected = new DriversLicense
{
Name = new Name
{
First = "MICHAEL",
Middle = "G",
Last = "MOTORIST"
},

Address = new Address
{
StreetLine1 = "12 MAIN AVE",
City = "WEST HAVEN",
JurisdictionCode = "CT",
PostalCode = "06516",
Country = Country.Usa
},

DateOfBirth = new DateTime(1961, 02, 04),
Sex = Sex.Male,
EyeColor = EyeColor.Brown,
Height = Height.FromImperial(5, 4),

IdNumber = "025995434",
AamvaVersionNumber = Version.Aamva2000,

IssueDate = new DateTime(2016, 11, 14),
ExpirationDate = new DateTime(2023, 02, 04),

IsOrganDonor = true,
Jurisdiction = new DriversLicenseJurisdiction
{
VehicleClass = "D"
}
};

var file = File.ReadAllText("Invalid Header.txt");
var idCard = Barcode.Parse(file, Validation.None);

AssertIdCard(expected, idCard);
AssertLicense(expected, idCard);

Assert.AreEqual("06516", idCard.Address.PostalCodeDisplay);
Assert.AreEqual("Connecticut", idCard.IssuerIdentificationNumber.GetDescription());
}
}
}
3 changes: 3 additions & 0 deletions IdParser.Test/IdParser.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<Content Include="IN License.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Invalid Header.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="KS License.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
18 changes: 18 additions & 0 deletions IdParser.Test/Invalid Header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@
6AAMVA6360060101DL00290179DAAMOTORIST,MICHAEL,G
DAG12 MAIN AVE
DAIWEST HAVEN
DAJCT
DAK06516
DAQ025995434
DARD
DAS
DAT
DBA20230204
DBB19610204
DBC1
DBD20161114
DAU504
DAYBRO
DBF00
DBHY
15 changes: 11 additions & 4 deletions IdParser/Fixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ private static string RemoveInvalidCharactersFromHeader(this string input)
return input;
}

var ansiPosition = input.IndexOf(Barcode.ExpectedFileType, StringComparison.CurrentCulture);
// AAMVA 2003+
var ansiPosition = input.IndexOf(Barcode.ExpectedFileType, StringComparison.Ordinal);

if (ansiPosition < 0)
if (ansiPosition >= 0)
{
return input;
return Barcode.ExpectedHeader + input.Substring(ansiPosition + Barcode.ExpectedFileType.Length);
}

input = Barcode.ExpectedHeader + input.Substring(ansiPosition + Barcode.ExpectedFileType.Length);
// AAMVA 2000 and earlier
var aamvaPosition = input.IndexOf("AAMVA", StringComparison.Ordinal);

if (aamvaPosition >= 0)
{
return Barcode.ExpectedHeader + input.Substring(aamvaPosition + Barcode.ExpectedFileType.Length);
}

return input;
}
Expand Down

0 comments on commit aebe300

Please sign in to comment.