Skip to content
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

YAML: incorrect parsing of curly brackets #439

Open
odyslam opened this issue Jun 7, 2023 · 2 comments
Open

YAML: incorrect parsing of curly brackets #439

odyslam opened this issue Jun 7, 2023 · 2 comments

Comments

@odyslam
Copy link

odyslam commented Jun 7, 2023

When parsing curly brackets, even as a string ("${env_var}"), it decodes the curly brackets to it's ASCII code. This is probably a bug of the underlying yaml library (yaml-rust).

I solved it by not using curly brackets.

@matthiasbeyer
Copy link
Collaborator

Hi!
Thanks for your report. I suspect that this is indeed an issue of the underlying yaml library, since this library does not interfere with parsing AFAIK.

I'll leave this open for discoverability until the yaml lib is fixed. If someone wants to contribute a test for this, I'd love to have that!

@polarathene
Copy link
Collaborator

polarathene commented Oct 20, 2023

Unable to reproduce (not much of a reproduction example given) with:

  • config v0.13.3
  • Windows via WSL2
  • cargo 1.73.0 (9c4383fb5 2023-08-26)

More context is required for this to be valid/reproducible.


Yaml file:

key: "${env_var}"

Rust reproduction main.rs:

use config::{Config, File, FileFormat};
use serde::Deserialize;

fn main() {
  let sources = ConfigSource::vec_example();

  for s in sources {
    let c = s.get_config();
    let test: Test = c.try_deserialize().unwrap();
    println!("{:#?}", test);
  }
}

#[allow(dead_code)]
#[derive(Debug, Deserialize)]
struct Test {
  key: String,
}

fn make<T>(source: T) -> Config
where
  T: config::Source + Send + Sync + 'static,
{
    Config::builder()
        .add_source(source)
        .build()
        .unwrap()
}

// Overkill:
enum ConfigSource {
  String(File<config::FileSourceString, FileFormat>),
  File(File<config::FileSourceFile, FileFormat>),
}

impl ConfigSource {
  fn vec_example() -> Vec<ConfigSource> {
    vec![
      ConfigSource::String(
        File::from_str(r#"key: "${env_var}""#, FileFormat::Yaml)
      ),
      ConfigSource::File(
        File::new("test.yml", FileFormat::Yaml)
      )
    ]
  }

  fn get_config(self) -> Config {
    match self {
      Self::String(s) => make(s),
      Self::File(f) => make(f),
    }
  }
}

Output:

Test {
    key: "${env_var}",
}
Test {
    key: "${env_var}",
}

Raw Config (not deserialized into Test struct):

Config {
    defaults: {},
    overrides: {},
    sources: [],
    cache: Value {
        origin: None,
        kind: Table(
            {
                "key": Value {
                    origin: None,
                    kind: String(
                        "${env_var}",
                    ),
                },
            },
        ),
    },
}

@matthiasbeyer matthiasbeyer modified the milestone: 0.14.0 Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants