diff --git a/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/parser/EpcQrCodeParser.kt b/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/parser/EpcQrCodeParser.kt index e70cdd3..90cf6cc 100644 --- a/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/parser/EpcQrCodeParser.kt +++ b/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/parser/EpcQrCodeParser.kt @@ -12,7 +12,10 @@ open class EpcQrCodeParser { val lines = decodedQrCode.split("\n", "\r\n") if (lines.size < 10 || lines.size > 12) { - return createInvalidFormatResult(decodedQrCode, "A EPC-QR-Code consists of 10 to 12 lines, but passed string has ${lines.size} lines") + val linesThatAreTooManyAreEmpty = lines.size > 12 && lines.subList(12, lines.size).all { it.isBlank() } + if (linesThatAreTooManyAreEmpty == false) { // even though it's against specification, but there are implementations out there that contain more the 12 lines. Ignore if they are empty + return createInvalidFormatResult(decodedQrCode, "A EPC-QR-Code consists of 10 to 12 lines, but passed string has ${lines.size} lines") + } } if (lines[0] != "BCD") { return createInvalidFormatResult(decodedQrCode, "A EPC-QR-Code's first lines has to be exactly 'BCD'") diff --git a/EpcQrCode/src/commonTest/kotlin/net.codinux.banking.epcqrcode/parser/EpcQrCodeParserTest.kt b/EpcQrCode/src/commonTest/kotlin/net.codinux.banking.epcqrcode/parser/EpcQrCodeParserTest.kt index 81ec55f..51cf885 100644 --- a/EpcQrCode/src/commonTest/kotlin/net.codinux.banking.epcqrcode/parser/EpcQrCodeParserTest.kt +++ b/EpcQrCode/src/commonTest/kotlin/net.codinux.banking.epcqrcode/parser/EpcQrCodeParserTest.kt @@ -170,6 +170,35 @@ Netter Text für den Zahlenden, damit dieser weiß, was er zahlt und auc } + @Test + fun moreThanSpecifiedLines() { + + // when + val result = underTest.parseEpcQrCode(""" + BCD + 002 + 1 + SCT + + Receiver + XX17LandMitLangerIBAN2345678901234 + EUR12345689.01 + + + + + +""".trimIndent()) + + // then + assertParsingSuccessful(result) + + assertEpcQrCode(result, EpcQrCodeVersion.Version2, EpcQrCodeCharacterSet.UTF_8, "SCT", null, "Receiver", + "XX17LandMitLangerIBAN2345678901234", "EUR", "12345689.01", null, null, + null, null) + } + + private fun assertParsingSuccessful(result: ParseEpcQrCodeResult) { assertTrue(result.successful) assertNull(result.error)