Skip to content

Commit e9281f3

Browse files
committed
fix: enhance template processing for single placeholders
- Updated `processTemplateRecursively` and `resolveDynamicDataInJson` to handle cases where only a single placeholder is present. - Improved nested data extraction and resolution logic for better accuracy in template processing.
1 parent f825778 commit e9281f3

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

packages/stac/lib/src/utils/template_utils.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ dynamic processTemplateRecursively(
7373
if (value.contains('{{') && value.contains('}}')) {
7474
String processedValue = value;
7575
final regex = RegExp(r'\{\{([^}]+)\}\}');
76-
final matches = regex.allMatches(value);
76+
final matches = regex.allMatches(value).toList();
77+
78+
if (matches.length == 1 && value.trim() == matches.first.group(0)) {
79+
final dataKey = matches.first.group(1)!.trim();
80+
final keys = dataKey.split('.');
81+
final dataValue = extractNestedData(data, keys);
82+
if (dataValue != null) {
83+
template[key] = dataValue;
84+
continue;
85+
}
86+
}
7787

7888
for (final match in matches) {
7989
final placeholder = match.group(0)!;
@@ -178,7 +188,15 @@ dynamic resolveDynamicDataInJson(dynamic json, BuildContext context) {
178188

179189
final regex = RegExp(r'\{\{([^}]+)\}\}');
180190
String result = json;
181-
final matches = regex.allMatches(json);
191+
final matches = regex.allMatches(json).toList();
192+
193+
if (matches.length == 1 && json.trim() == matches.first.group(0)) {
194+
final expression = matches.first.group(1)!.trim();
195+
final resolved = scope.resolveExpression(expression);
196+
if (resolved != null) {
197+
return resolved;
198+
}
199+
}
182200

183201
for (final match in matches) {
184202
final placeholder = match.group(0)!;

0 commit comments

Comments
 (0)