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

Nested arrays badly mangled #464

Closed
ijackson opened this issue Oct 4, 2023 · 0 comments · Fixed by #465
Closed

Nested arrays badly mangled #464

ijackson opened this issue Oct 4, 2023 · 0 comments · Fixed by #465

Comments

@ijackson
Copy link
Contributor

ijackson commented Oct 4, 2023

To reproduce:

    #[test]
    fn list() {
        let jtxt = r#" { "proxy_ports": [ [1,2] ] } "#;
        let jval: serde_json::Value = serde_json::from_str(jtxt).unwrap();
        //dbg!(&jval);
        let jcfg = config::Config::try_from(&jval).unwrap();
        //dbg!(&jcfg);
        let jret: serde_json::Value = jcfg.clone().try_deserialize().unwrap();
        println!("json roundtrip: {jret:#?}");

        let ttxt = r#" proxy_ports = [ [1,2] ] "#;
        let tval: toml::Value = toml::from_str(ttxt).unwrap();
        //dbg!(&tval);
        let tcfg = config::Config::try_from(&tval).unwrap();
        //dbg!(&tcfg);
        let tret: Result<String, _> = tcfg.clone().try_deserialize()
            .map(|v: toml::Value| toml::to_string(&v).unwrap());
        println!("toml roundtrip: {tret:#?}");
    }

Expected output:

json roundtrip: Object {
    "proxy_ports": Array [
        Array [
            Number(1),
            Number(2),
        ],
    ],
}
toml roundtrip: Ok(
    "proxy_ports = [[1, 2]]\n"
)

Actual output:

json roundtrip: Object {
    "proxy_ports": Array [
        Null,
        Number(1),
        Number(2),
    ],
}
toml roundtrip: Err(
    invalid type: unit value, expected any valid TOML value,
)

Uncommenting the dbgs in the repro above shows this, which seems entirely wrong:

[crates/arti/src/onion_proxy.rs:143] &jcfg = Config {
    defaults: {},
    overrides: {
        Subscript(
            Identifier(
                "proxy_ports",
            ),
            1,
        ): Value {
            origin: None,
            kind: I64(
                1,
            ),
        },
        Subscript(
            Identifier(
                "proxy_ports",
            ),
            2,
        ): Value {
            origin: None,
            kind: I64(
                2,
            ),
        },
    },
    sources: [],
    cache: Value {
        origin: None,
        kind: Table(
            {
                "proxy_ports": Value {
                    origin: None,
                    kind: Array(
                        [
                            Value {
                                origin: None,
                                kind: Nil,
                            },
                            Value {
                                origin: None,
                                kind: I64(
                                    1,
                                ),
                            },
                            Value {
                                origin: None,
                                kind: I64(
                                    2,
                                ),
                            },
                        ],
                    ),
                },
            },
        ),
    },
}
zydou pushed a commit to zydou/arti that referenced this issue Nov 30, 2023
This version of the config crate includes a fix for the issue
(mehcode/config-rs#464)
that had prevented us from using the format we had wanted for
our rproxy configuration.
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

Successfully merging a pull request may close this issue.

1 participant