diff --git a/v2/README.md b/v2/README.md
index b82195b..9c9fdb7 100644
--- a/v2/README.md
+++ b/v2/README.md
@@ -33,6 +33,10 @@ Some improvements to check, later:
Version Changes Control
=======================
+v2.1.6 - 2023-05-25
+-----------------------
+- Bug corrected into GetCollection(id) function, if the dataset is not an XDatasetCollection, it should return nil, not a panic error
+
v2.1.5 - 2023-05-17
-----------------------
- Bump golang.org/x/text from 0.3.5 to 0.3.8 for security upgrade
diff --git a/v2/go.sum b/v2/go.sum
index b7904af..5f6250b 100644
--- a/v2/go.sum
+++ b/v2/go.sum
@@ -1,5 +1,29 @@
+github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
+golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
diff --git a/v2/xcore.go b/v2/xcore.go
index 2143e55..16f6830 100644
--- a/v2/xcore.go
+++ b/v2/xcore.go
@@ -868,7 +868,7 @@
package xcore
// VERSION is the used version nombre of the XCore library.
-const VERSION = "2.1.5"
+const VERSION = "2.1.6"
// LOG is the flag to activate logging on the library.
// if LOG is set to TRUE, LOG indicates to the XCore libraries to log a trace of functions called, with most important parameters.
diff --git a/v2/xdatasetcollection.go b/v2/xdatasetcollection.go
index d312f63..7e015fa 100644
--- a/v2/xdatasetcollection.go
+++ b/v2/xdatasetcollection.go
@@ -142,7 +142,10 @@ func (d *XDatasetCollection) GetCollection(key string) (XDatasetCollectionDef, b
v, ok := d.GetData(key)
// Verify v IS actually a XDatasetCollectionDef to avoid the error
if ok {
- return v.(XDatasetCollectionDef), true
+ dsd, ok2 := v.(XDatasetCollectionDef)
+ if ok2 {
+ return dsd, true
+ }
}
return nil, false
}
diff --git a/v2/xtemplate_test.go b/v2/xtemplate_test.go
index 8143177..0a6ad7e 100644
--- a/v2/xtemplate_test.go
+++ b/v2/xtemplate_test.go
@@ -41,7 +41,7 @@ I love {{name}}
// I love Videogames
}
-func ExampleNewXTemplateEmptyLoop() {
+func TestNewXTemplateEmptyLoop(t *testing.T) {
tmpl, _ := NewXTemplateFromString(`
%-- This is a comment. It will not appear in the final code. --%
Let's put your name here: {{clientname}}
@@ -69,6 +69,36 @@ I love nothing
// I love nothing
}
+func TestNewXTemplateNilCollection(t *testing.T) {
+
+ tmpl, _ := NewXTemplateFromString(`
+%-- This is a comment. It will not appear in the final code. --%
+Let's put your name here: {{clientname}}
+And lets put your hobbies here:
+%-- note the 1rst id is the entry into the data to inject and the second one is the name of the sub-template to use --%
+@@hobbies@@
+%-- And you need the template for each hobby:--%
+[[hobbies]]
+I love {{name}}
+[[]]
+[[hobbies.none]]
+I love nothing
+[[]]
+`)
+ // The creation of the data is obviously tedious here, in real life it should come from a JSON, a Database, etc
+ var col XDatasetCollection
+ data := XDataset{
+ "clientname": "Fred",
+ "hobbies": col,
+ }
+
+ fmt.Println(tmpl.Execute(&data))
+ // Output:
+ // Let's put your name here: Fred
+ // And lets put your hobbies here:
+ // I love nothing
+}
+
func TestNewXTemplateFromString(t *testing.T) {
tmpl, _ := NewXTemplateFromString(`
%-- This is a comment. It will not appear in the final code. --%