Parse a YAML value string into a serde_json::Value.
(s: &str)
| 896 | |
| 897 | /// Parse a YAML value string into a serde_json::Value. |
| 898 | fn parse_yaml_value(s: &str) -> serde_json::Value { |
| 899 | // Remove surrounding quotes if present |
| 900 | let s = |
| 901 | if (s.starts_with('"') && s.ends_with('"')) || (s.starts_with('\'') && s.ends_with('\'')) { |
| 902 | &s[1..s.len() - 1] |
| 903 | } else { |
| 904 | s |
| 905 | }; |
| 906 | |
| 907 | // Try as integer |
| 908 | if let Ok(n) = s.parse::<i64>() { |
| 909 | return serde_json::Value::Number(n.into()); |
| 910 | } |
| 911 | // Try as float |
| 912 | if let Ok(n) = s.parse::<f64>() { |
| 913 | if let Some(n) = serde_json::Number::from_f64(n) { |
| 914 | return serde_json::Value::Number(n); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | // Try as boolean / null |
| 919 | match s { |
| 920 | "true" => return serde_json::Value::Bool(true), |
| 921 | "false" => return serde_json::Value::Bool(false), |
| 922 | "null" => return serde_json::Value::Null, |
| 923 | _ => {} |
| 924 | } |
| 925 | |
| 926 | // Try as array [a, b, c] |
| 927 | if s.starts_with('[') && s.ends_with(']') { |
| 928 | let inner = s[1..s.len() - 1].trim(); |
| 929 | if inner.is_empty() { |
| 930 | return serde_json::Value::Array(Vec::new()); |
| 931 | } |
| 932 | let items: Vec<serde_json::Value> = inner |
| 933 | .split(',') |
| 934 | .map(|item| parse_yaml_value(item.trim())) |
| 935 | .collect(); |
| 936 | return serde_json::Value::Array(items); |
| 937 | } |
| 938 | |
| 939 | // Try as inline JSON object |
| 940 | if s.starts_with('{') && s.ends_with('}') { |
| 941 | if let Ok(v) = serde_json::from_str::<serde_json::Value>(s) { |
| 942 | return v; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | // Default: string |
| 947 | serde_json::Value::String(s.to_string()) |
| 948 | } |
| 949 | |
| 950 | /// Infer the vault entry type from its path. |
| 951 | fn infer_entry_type(path: &str) -> VaultEntryType { |
no test coverage detected