fix(context): make sure to actually iterate longest first for key replacement

This commit is contained in:
2025-10-24 19:37:06 -07:00
parent 057c48f9f7
commit 2253fa2a1f

View File

@@ -2,6 +2,7 @@ use crate::actions::ActionDeclaration;
use crate::options::SproutOptions; use crate::options::SproutOptions;
use anyhow::anyhow; use anyhow::anyhow;
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use std::cmp::Reverse;
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use std::rc::Rc; use std::rc::Rc;
use uefi::proto::device_path::DevicePath; use uefi::proto::device_path::DevicePath;
@@ -204,7 +205,9 @@ impl SproutContext {
// Sort the keys by length. This is to ensure that we stamp the longest keys first. // Sort the keys by length. This is to ensure that we stamp the longest keys first.
// If we did not do this, "$abc" could be stamped by "$a" into an invalid result. // If we did not do this, "$abc" could be stamped by "$a" into an invalid result.
let mut keys = values.keys().collect::<Vec<_>>(); let mut keys = values.keys().collect::<Vec<_>>();
keys.sort_by_key(|key| key.len());
// Sort by key length, reversed. This results in the longest keys appearing first.
keys.sort_by_key(|key| Reverse(key.len()));
for key in keys { for key in keys {
// Empty keys are not supported. // Empty keys are not supported.