From 9ff8bef5a445dd080fb7d4e9725f429851171132 Mon Sep 17 00:00:00 2001 From: ArmanKolozyan <92608959+ArmanKolozyan@users.noreply.github.com> Date: Tue, 23 Dec 2025 17:22:33 +0100 Subject: [PATCH] Fix: InvalidMRZKey error for TD1 overflow format --- app/ios/PassportReader.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/ios/PassportReader.swift b/app/ios/PassportReader.swift index 4a54c24d0..dfa1107c0 100644 --- a/app/ios/PassportReader.swift +++ b/app/ios/PassportReader.swift @@ -119,9 +119,14 @@ class PassportReader: NSObject { } func pad( _ value : String, fieldLength:Int ) -> String { - // Pad out field lengths with < if they are too short - let paddedValue = (value + String(repeating: "<", count: fieldLength)).prefix(fieldLength) - return String(paddedValue) + // for values shorter than fieldLength, we pad with < characters + // for values equal to or longer than fieldLength, we use the value as-is (we don't truncate) + // this is critical for TD1 documents with overflow format where document numbers exceed 9 characters + if value.count >= fieldLength { + return value + } + let paddedValue = value + String(repeating: "<", count: fieldLength - value.count) + return paddedValue } func calcCheckSum( _ checkString : String ) -> Int {