-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Address Copilot code review suggestions #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -239,6 +239,18 @@ impl Environment { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Normalize a key for storage in the flat map based on nested mode setting. | ||||||
| /// | ||||||
| /// In nested mode, preserves the original case for proper splitting. | ||||||
| /// In flat mode, converts to lowercase for backward compatibility. | ||||||
| fn normalize_key(&self, key: &str) -> String { | ||||||
| if self.nested { | ||||||
| key.to_string() | ||||||
| } else { | ||||||
| key.to_lowercase() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| fn parse_env_value(value: &str) -> Value { | ||||||
| if let Ok(b) = value.parse::<bool>() { | ||||||
| return json!(b); | ||||||
|
|
@@ -272,19 +284,19 @@ impl Environment { | |||||
| /// This helper function takes a flat key path (e.g., ["http", "server", "port"]) | ||||||
| /// and creates the necessary nested structure in the map, inserting the value | ||||||
| /// at the deepest level. | ||||||
| fn insert_nested(map: &mut Map<String, Value>, parts: &[&str], value: Value) { | ||||||
| fn insert_nested(map: &mut Map<String, Value>, parts: &[String], value: Value) { | ||||||
| if parts.is_empty() { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| if parts.len() == 1 { | ||||||
| // Base case: insert the value at this key | ||||||
| map.insert(parts[0].to_string(), value); | ||||||
| map.insert(parts[0].clone(), value); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| // Recursive case: get or create the nested object | ||||||
| let key = parts[0].to_string(); | ||||||
| let key = parts[0].clone(); | ||||||
| match map.entry(key) { | ||||||
| serde_json::map::Entry::Occupied(mut occ) => { | ||||||
| if let Value::Object(ref mut nested) = occ.get_mut() { | ||||||
|
|
@@ -365,12 +377,7 @@ impl Environment { | |||||
|
|
||||||
| if key_check.starts_with(&prefix_str) { | ||||||
| let trimmed = key_check[prefix_str.len()..].trim_start_matches(&self.separator); | ||||||
| // Keep case for nested mode, lowercase for flat mode | ||||||
| let key_for_map = if self.nested { | ||||||
| trimmed.to_string() | ||||||
| } else { | ||||||
| trimmed.to_lowercase() | ||||||
| }; | ||||||
| let key_for_map = self.normalize_key(trimmed); | ||||||
|
Comment on lines
379
to
+380
|
||||||
| flat_map.insert(key_for_map, Self::parse_env_value(&value)); | ||||||
| } | ||||||
| } else { | ||||||
|
|
@@ -395,12 +402,7 @@ impl Environment { | |||||
|
|
||||||
| if key_check.starts_with(&prefix_str) { | ||||||
| let trimmed = key_check[prefix_str.len()..].trim_start_matches(&self.separator); | ||||||
|
||||||
| let trimmed = key_check[prefix_str.len()..].trim_start_matches(&self.separator); | |
| let trimmed = override_key[prefix_str.len()..].trim_start_matches(&self.separator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
normalize_keymethod preserves case in nested mode, but lines 424 and 428-429 unconditionally lowercase keys even in nested mode. This creates an inconsistency: keys stored inflat_mapvianormalize_key(lines 380, 405) preserve case in nested mode, but when split and inserted intoresult(lines 424, 428-429), they are lowercased. This breaks the intended behavior documented in the method's comment. Either remove the lowercasing at lines 424 and 428-429 when in nested mode, or updatenormalize_keyto always lowercase.