Skip to content

Commit

Permalink
fixing some null pointer issues during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
davydotcom committed Apr 20, 2023
1 parent ef1de91 commit 6e885fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {

## What's New

* **0.6.9** Fixed some null pointer issues if content on base64encode was null and some exceptions on array traversal
* **0.6.8** Fixed ! (not) operator and added base64encode, base64decode, textdecodebase64, textencodebase64
* **0.6.7** Fixed operators called on variables without spaces
* **0.6.6** Fixed nested strings inside an interpolation syntax as well as some add conditional checks
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ext {


group = 'com.bertramlabs.plugins'
version = '0.6.8'
version = '0.6.9'

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
sourceCompatibility = "1.8"
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/com/bertramlabs/plugins/hcl4j/HCLBaseFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,21 @@ static void registerCastingFunctions(HCLParser parser) {
parser.registerFunction("base64encode", (arguments) -> {
if(arguments.size() > 0) {
String content = (String)(arguments.get(0));
return Base64.getEncoder().encodeToString(content.getBytes(StandardCharsets.UTF_8));
if(content != null) {
return Base64.getEncoder().encodeToString(content.getBytes(StandardCharsets.UTF_8));
}
}
return null;
});

parser.registerFunction("base64decode", (arguments) -> {
if(arguments.size() > 0) {
String content = (String)(arguments.get(0));
byte[] decodedBytes = Base64.getDecoder().decode(content);
return new String(decodedBytes,StandardCharsets.UTF_8);
if(content != null) {
byte[] decodedBytes = Base64.getDecoder().decode(content);
return new String(decodedBytes,StandardCharsets.UTF_8);
}

}
return null;
});
Expand All @@ -421,18 +426,23 @@ static void registerCastingFunctions(HCLParser parser) {
if(arguments.size() > 1) {
String content = (String)(arguments.get(0));
String encoding = (String)(arguments.get(1));
return Base64.getEncoder().encodeToString(content.getBytes(Charset.forName(encoding)));
if(content != null) {
return Base64.getEncoder().encodeToString(content.getBytes(Charset.forName(encoding)));
}
}
return null;
});

parser.registerFunction("textdecodebase64", (arguments) -> {
if(arguments.size() > 1) {
String content = (String)(arguments.get(0));
String encoding = (String)(arguments.get(1));
if(content != null) {
String encoding = (String)(arguments.get(1));

byte[] decodedBytes = Base64.getDecoder().decode(content);
return new String(decodedBytes,Charset.forName(encoding));
byte[] decodedBytes = Base64.getDecoder().decode(content);
return new String(decodedBytes,Charset.forName(encoding));
}

}
return null;
});
Expand Down

0 comments on commit 6e885fc

Please sign in to comment.