From a85553c526ad964394bfb9fd70a172f784f78cfb Mon Sep 17 00:00:00 2001 From: David Estes Date: Tue, 2 May 2023 18:18:51 -0400 Subject: [PATCH] fixing parser issue with hcl --- README.md | 3 ++- build.gradle | 2 +- .../java/com/bertramlabs/plugins/hcl4j/HCLParser.java | 10 ++++++++++ .../com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6cc05ca..94666bb 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,13 @@ Using gradle one can include the hcl4j dependency like so: ```groovy dependencies { - compile "com.bertramlabs.plugins:hcl4j:0.7.0" + compile "com.bertramlabs.plugins:hcl4j:0.7.2" } ``` ## What's New +* **0.7.2** Handling nested Block types in a List as a non null value * **0.7.1** Adding some parser exception safety and added slf4j dependency for logging errors * **0.7.0** Adding some null safety on some of the base functions * **0.6.9** Fixed some null pointer issues if content on base64encode was null and some exceptions on array traversal diff --git a/build.gradle b/build.gradle index 6c7e504..3d70994 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { group = 'com.bertramlabs.plugins' -version = '0.7.1' +version = '0.7.2' ext.isReleaseVersion = !version.endsWith("SNAPSHOT") sourceCompatibility = "1.8" diff --git a/src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java b/src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java index 7513a41..7193cde 100644 --- a/src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java +++ b/src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java @@ -435,9 +435,19 @@ private Object processSymbolPass2(Object val, Map mapPosition) th } } return nestedMap; + } else if(val instanceof HCLBlock) { + HCLBlock symbol = (HCLBlock)(val); + Map nestedMap = new LinkedHashMap<>(); + if((symbol.getChildren() != null)) { + for(Symbol child : symbol.getChildren()) { + processSymbolPass2(child, nestedMap); + } + } + return nestedMap; } else if(val instanceof HCLArray) { HCLArray symbol = (HCLArray)(val); if(symbol.getChildren() != null) { + List objectList = new ArrayList<>(); for(Symbol child : symbol.getChildren()) { Map nestedMap = new LinkedHashMap<>(); diff --git a/src/test/groovy/com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy b/src/test/groovy/com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy index 8785144..69ca6d5 100644 --- a/src/test/groovy/com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy +++ b/src/test/groovy/com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy @@ -722,6 +722,7 @@ array_set = [{ println JsonOutput.prettyPrint(JsonOutput.toJson(results)); then: results.array_set?.size() == 2 + results.array_set[1].blah == "test2" } void "it should handle end of line comments with hyphens"() {