|
43 | 43 | //! # run().unwrap() |
44 | 44 | //! ``` |
45 | 45 |
|
| 46 | +use crate::static_regex; |
46 | 47 | use crate::utils::{TomlExt, fs, log_backtrace}; |
47 | 48 | use anyhow::{Context, Error, Result, bail}; |
48 | 49 | use serde::{Deserialize, Serialize}; |
@@ -149,15 +150,23 @@ impl Config { |
149 | 150 | pub fn update_from_env(&mut self) -> Result<()> { |
150 | 151 | debug!("Updating the config from environment variables"); |
151 | 152 |
|
| 153 | + static_regex!( |
| 154 | + VALID_KEY, |
| 155 | + r"^(:?book|build|rust|output|preprocessor)(:?$|\.)" |
| 156 | + ); |
| 157 | + |
152 | 158 | let overrides = |
153 | 159 | env::vars().filter_map(|(key, value)| parse_env(&key).map(|index| (index, value))); |
154 | 160 |
|
155 | 161 | for (key, value) in overrides { |
156 | | - if key == "log" { |
157 | | - // MDBOOK_LOG is used to control logging. |
| 162 | + trace!("{} => {}", key, value); |
| 163 | + if !VALID_KEY.is_match(&key) { |
| 164 | + // Ignore environment variables for other top-level things. |
| 165 | + // This allows users to set things like `MDBOOK_VERSION` or |
| 166 | + // `MDBOOK_DOWNLOAD_URL` for their own scripts and not |
| 167 | + // interfere with how the config is loaded. |
158 | 168 | continue; |
159 | 169 | } |
160 | | - trace!("{} => {}", key, value); |
161 | 170 | let parsed_value = serde_json::from_str(&value) |
162 | 171 | .unwrap_or_else(|_| serde_json::Value::String(value.to_string())); |
163 | 172 |
|
|
0 commit comments