Implemented that if QR Code text has more than 12 lines, ignoring them if they are empty
This commit is contained in:
parent
86e59cc0cc
commit
ba264e74dd
|
@ -12,7 +12,10 @@ open class EpcQrCodeParser {
|
||||||
val lines = decodedQrCode.split("\n", "\r\n")
|
val lines = decodedQrCode.split("\n", "\r\n")
|
||||||
|
|
||||||
if (lines.size < 10 || lines.size > 12) {
|
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") {
|
if (lines[0] != "BCD") {
|
||||||
return createInvalidFormatResult(decodedQrCode, "A EPC-QR-Code's first lines has to be exactly 'BCD'")
|
return createInvalidFormatResult(decodedQrCode, "A EPC-QR-Code's first lines has to be exactly 'BCD'")
|
||||||
|
|
|
@ -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) {
|
private fun assertParsingSuccessful(result: ParseEpcQrCodeResult) {
|
||||||
assertTrue(result.successful)
|
assertTrue(result.successful)
|
||||||
assertNull(result.error)
|
assertNull(result.error)
|
||||||
|
|
Loading…
Reference in New Issue