mirror of
https://github.com/edera-dev/sprout.git
synced 2026-11-04 17:52:20 +00:00
fix(boot): resolve values that refer to other values when stamping
This commit is contained in:
1 parent
ab9f3cd2d3
commit
98f0298737
1 file changed
+13
-1
@@ -233,7 +233,19 @@ impl SproutContext {
|
|||||||
/// For example, if this context contains {"a":"b"}, and the text "hello\\$a", it will produce
|
/// For example, if this context contains {"a":"b"}, and the text "hello\\$a", it will produce
|
||||||
/// "hello\\b" as an output string.
|
/// "hello\\b" as an output string.
|
||||||
pub fn stamp(&self, text: impl AsRef<str>) -> String {
|
pub fn stamp(&self, text: impl AsRef<str>) -> String {
|
||||||
stamp_values(&self.all_values(), text.as_ref()).1
|
// A value can refer to other values, which a single pass leaves unresolved when the
|
||||||
|
// key it refers to was already handled. Stamp until the text settles, up to the same
|
||||||
|
// limit that finalizing a context uses.
|
||||||
|
let values = self.all_values();
|
||||||
|
let mut result = text.as_ref().to_string();
|
||||||
|
for _ in 0..CONTEXT_FINALIZE_ITERATION_LIMIT {
|
||||||
|
let (changed, stamped) = stamp_values(&values, &result);
|
||||||
|
result = stamped;
|
||||||
|
if !changed || result.len() > CONTEXT_FINALIZE_VALUE_LENGTH_LIMIT {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stamps all the items from the iterator `input` with all the values in this [SproutContext]
|
/// Stamps all the items from the iterator `input` with all the values in this [SproutContext]
|
||||||
|
|||||||
Reference in new issue
Block a user