Skip to content

Commit 81cd731

Browse files
committed
Fixed endless recursion when scanning non EAN13 codes starting with 0 that will not result in a
match on the database
1 parent 7ea8728 commit 81cd731

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.10.4]
5+
6+
### Fixed
7+
- Endless recursion when scanning non EAN13 codes starting with 0 that will not result in a
8+
match on the database
9+
410
## [0.10.3]
511

612
### Added

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ allprojects {
2424
}
2525

2626
project.ext {
27-
sdkVersion='0.10.3'
27+
sdkVersion='0.10.4'
2828
versionCode=1
2929

3030
compileSdkVersion=28

core/src/main/java/io/snabble/sdk/ShoppingCart.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,14 @@ private void setScannedCodeForEntry(Entry entry, ScannableCode scannedCode) {
352352
notifyQuantityChanged(this, entry.product);
353353
}
354354

355+
private String findCodeByScannedCode(Product product, ScannableCode scannableCode) {
356+
String code = findCodeByScannedCodeInternal(product, scannableCode, true);
357+
return code != null ? code : scannableCode.getCode();
358+
}
359+
355360
// finds the code matching the code in the product if it was scanned with leading zeros
356361
// and the leading zeros are missing in the scannableCodes of the product
357-
private String findCodeByScannedCode(Product product, ScannableCode scannableCode) {
362+
private String findCodeByScannedCodeInternal(Product product, ScannableCode scannableCode, boolean recursive) {
358363
String scannedCode = scannableCode.getCode();
359364

360365
for (String code : product.getScannableCodes()) {
@@ -363,15 +368,17 @@ private String findCodeByScannedCode(Product product, ScannableCode scannableCod
363368
}
364369
}
365370

366-
if (scannedCode.length() > 0 && scannedCode.startsWith("0")) {
367-
scannedCode = scannedCode.substring(1, scannedCode.length());
368-
return findCodeByScannedCode(product, ScannableCode.parse(project, scannedCode));
369-
} else if (scannedCode.length() < 13) {
370-
scannedCode = StringUtils.repeat('0', 13 - scannedCode.length()) + scannedCode;
371-
return findCodeByScannedCode(product, ScannableCode.parse(project, scannedCode));
371+
if (recursive) {
372+
if (scannedCode.length() > 0 && scannedCode.startsWith("0")) {
373+
scannedCode = scannedCode.substring(1, scannedCode.length());
374+
return findCodeByScannedCodeInternal(product, ScannableCode.parse(project, scannedCode), true);
375+
} else if (scannedCode.length() < 13) {
376+
scannedCode = StringUtils.repeat('0', 13 - scannedCode.length()) + scannedCode;
377+
return findCodeByScannedCodeInternal(product, ScannableCode.parse(project, scannedCode), false);
378+
}
372379
}
373380

374-
return scannedCode;
381+
return null;
375382
}
376383

377384
private int indexOf(Entry e) {

0 commit comments

Comments
 (0)