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

Feature request: case-insensitive keys when Unmarshalling ? #123

Open
moul opened this issue Sep 8, 2015 · 5 comments
Open

Feature request: case-insensitive keys when Unmarshalling ? #123

moul opened this issue Sep 8, 2015 · 5 comments

Comments

@moul
Copy link

moul commented Sep 8, 2015

So we can load files like these:

hosts:
  toto:
    hostname: 1.2.3.4
    port: 42

As well as

Hosts:
  toto:
    HostName: 1.2.3.4
    Port: 42

Using

type File struct {
  Hosts: []Host `yaml:Hosts`,
}

type Host struct {
  HostName: string `yaml:HostName`
  Port: int `yaml:Port`
}
@dhiltonp
Copy link

For this, I'm running ToLower on the input data; considering that case sensitivity is part of the yaml spec, I think it's a better solution than changing the library (although it may be less convenient).

jpap added a commit to jpap/yaml that referenced this issue Oct 1, 2019
jpap added a commit to jpap/yaml that referenced this issue Oct 1, 2019
@jpap
Copy link

jpap commented Oct 1, 2019

@dhiltonp, would love if you have a little time to review my PR so we can resolve this 3+ year old issue. I've also run into the same problem, where I'd like to ignore case-sensitivity on unmarshal.

@moul
Copy link
Author

moul commented Oct 9, 2019

Additional note, it's important to only ignore case-sensitivity for the key; the value should not be lowered

As a workaround I made this: https://github.com/moul/flexyaml

I would love to depreciate this repo in favor of an official solution :)

@jpap
Copy link

jpap commented Oct 9, 2019

@moul, my PR only considers case insensitivity for the key; the value is kept as-is.

Looking at the mounting PRs backed up over a year, I'm wondering whether this project is still being maintained. I'm going to be working from a fork, unfortunately. In your case, you might do the same; feel free to include my PR if that suits your needs.

@frickenate
Copy link

What the actual hell. We all understand the limitation of the first character having to be uppercase due to export requirements... but yaml is case-sensitive. Where the hell does "unmarshalled using the field name lowercased as the default key" come from?!

You're making me tag every.... single... fkn field that has an uppercase character in it. Clearly my InstallVersion field should be accepting the yaml field for installVersion... not installversion. For fuck's sake. Almost every... damn... field... has to be remapped manually. Not because my fields are strange, but because you arbitrarily decided on some absurd and broken "lowercase all the things".

Fix this in a v3 please. Backwards-incompatible as hell, but you'll be restoring expected behaviour. We're not even asking for complete case-insensitivity. Just that beyond that first unfortunate letter due to exported fields, you don't touch the rest of the string.

2 hours of my life wasted just to understand this "gotcha". And now every time I unmarshal, I have to work around this bug. And yes, it's a bug. No excuses, this is a bug. You're actually removing case-sensitivity from a case-sensitive format.

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.

4 participants