c0shea/IdParser

Fails to parse a CO license

Creator-Bala opened this issue · 3 comments

Hi,
I was testing a specific CO state license and was getting a parsing error due to empty string in subfileRecord. Can you please modify the below method with the new validation check to continue when length is less than 3. If you want that specific DL details, let me know and I can remove the basic data and share it across.

    /// <summary>
    /// Parses the country based on the DCG subfile record.
    /// Gets the country from the IIN if no matching subfile record was found.
    /// </summary>
    private static Country ParseCountry(IssuerIdentificationNumber iin, Version version, List<string> subfileRecords)
    {
        // Country is not a subfile record in the AAMVA 2000 standard
        if (version == Version.Aamva2000)
        {
            return Country.Usa;
        }

        foreach (var subfileRecord in subfileRecords)
        {
            if (subfileRecord.Length < 3)
            {
                continue;
            }

            var elementId = subfileRecord.Substring(0, 3);
            var data = subfileRecord.Substring(3).Trim();

            if (elementId == "DCG")
            {
                if (data == "USA")
                {
                    return Country.Usa;
                }
                if (data == "CAN" || data == "CDN")
                {
                    return Country.Canada;
                }
            }
        }

        return iin.GetCountry();
    }

Thanks!
Bala

Do you have an anonymized example of the CO license? I'd like to add a unit test before making this change.

"@\n\u001e\rANSI 636020080002DL00410266ZC03040010DL\nDCAR\nDCBNONE\nDCD\nDBA01022022\nDCSYYYYYYYY\nDACXXXXXXXX\nDADLYNN\nDBD12292016\nDBB02021972\nDBC2\nDAYGRN\nDAU063 in\nDAG99999 W 22ST AVE\nDAILAKEWOOD\nDAJCO\nDAK804010000 \nDAQ121360319\nDCF16364434969\nDCGUSA\nDDEU\nDDFU\nDDGU\nDCJ20170103_000117_3_3776\nDCUDDAF\nDDB10302015\nDDD\nZCZCANONE\r"

The above string is what the parser was trying to parse. I've anonymized the data as best as I could without affecting the string. Hope that's helpful.

The 2013 version of the Colorado license doesn't seem to follow the standard. The first subfile record is expected immediately after DL or ID, but instead there is a newline before DCA. I added support to work around this in 1441fa2