Skip to content

Commit

Permalink
Enhancement: Allowing zero length in static array (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu authored Nov 29, 2022
1 parent d4ebc32 commit 276a4ae
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/algorand/algosdk/abi/ABIType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public abstract class ABIType {
public static final int ABI_DYNAMIC_HEAD_BYTE_LEN = 2;
private static final Pattern staticArrayPattern = Pattern.compile("^(?<elemT>[a-z\\d\\[\\](),]+)\\[(?<len>[1-9][\\d]*)]$");
private static final Pattern staticArrayPattern = Pattern.compile("^(?<elemT>[a-z\\d\\[\\](),]+)\\[(?<len>0|[1-9][\\d]*)]$");
private static final Pattern ufixedPattern = Pattern.compile("^ufixed(?<size>[1-9][\\d]*)x(?<precision>[1-9][\\d]*)$");

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/algorand/algosdk/abi/TypeArrayStatic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class TypeArrayStatic extends ABIType {
public final int length;

public TypeArrayStatic(ABIType elemType, int length) {
if (length < 1)
throw new IllegalArgumentException("static-array initialize failure: array length should be at least 1");
if (length < 0)
throw new IllegalArgumentException("static-array initialize failure: array length should be non-negative");
this.elemType = elemType;
this.length = length;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/algorand/algosdk/abi/TestTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void TestTypeFromStringInvalid() {
"[][][]",
"stuff[]",
// static array
"ufixed32x10[0]",
"bool[01]",
"byte[10 ]",
"uint64[0x21]",
// tuple
Expand Down

0 comments on commit 276a4ae

Please sign in to comment.