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.parse parses key 0: as string instead of Int64 #6156

Closed
Blacksmoke16 opened this issue Jun 3, 2018 · 2 comments
Closed

YAML.parse parses key 0: as string instead of Int64 #6156

Blacksmoke16 opened this issue Jun 3, 2018 · 2 comments

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Jun 3, 2018

Take the following yaml data:

yaml_data = %(
10:
    description:
        de: 'Ein Hauptreihenstern einer Klasse von Himmelskörpern, die sich typischerweise
            durch eine weiße oder weiß-gelbe Färbung auszeichnen. Die Energieerzeugung
            dieser Sterne wird durch Wasserstofffusion angetrieben und sie sind oft
            sehr heiß und hell.'
    graphicID: 21466
    groupID: 6
    mass: 1000000000000000000
    name:
        de: Sun F0 (White)
        en: Sun F0 (White)
        fr: Soleil F0 (blanche)
        ja: 恒星F0(ホワイト)
        ru: Sun F0 (White)
        zh: 恒星F0 (白色)
    portionSize: 1
    published: false
    radius: 10000
    soundID: 20098
    volume: 1
0:
    groupID: 0
    mass: 1.0
    name:
        de: '#System'
        en: '#System'
        fr: '#Système'
        ja: '#システム'
        ru: '#Система'
        zh: '#星系'
    portionSize: 1
    published: false
2:
    groupID: 2
    name:
        de: Corporation
        en: Corporation
        fr: Corporation
        ja: コーポレーション
        ru: Corporation
        zh: 军团
    portionSize: 1
    published: false
3:
    groupID: 3
    name:
        de: Region
        en: Region
        fr: Région
        ja: リージョン
        ru: Region
        zh: 星域
    portionSize: 1
    published: false
    volume: 1.0
)

When doing a YAML.parse on the yaml data, all the keys except for 0 are casted as an Int64, while 0 is casted as a string.

https://play.crystal-lang.org/#/r/47be/edit

require "yaml"  

  yaml = YAML.parse(yaml_data)

  p yaml
{10_i64 =>
  {"description" =>
    {"de" =>
      "Ein Hauptreihenstern einer Klasse von Himmelskörpern, die sich typischerweise durch eine weiße oder weiß-gelbe Färbung auszeichnen. Die Energieerzeugung dieser Sterne wird durch Wasserstofffusion angetrieben und sie sind oft sehr heiß und hell."},
   "graphicID" => 21466_i64,
   "groupID" => 6_i64,
   "mass" => 1000000000000000000_i64,
   "name" =>
    {"de" => "Sun F0 (White)",
     "en" => "Sun F0 (White)",
     "fr" => "Soleil F0 (blanche)",
     "ja" => "恒星F0(ホワイト)",
     "ru" => "Sun F0 (White)",
     "zh" => "恒星F0 (白色)"},
   "portionSize" => 1_i64,
   "published" => false,
   "radius" => 10000_i64,
   "soundID" => 20098_i64,
   "volume" => 1_i64},
 "0" =>
  {"groupID" => "0",
   "mass" => 1.0,
   "name" =>
    {"de" => "#System",
     "en" => "#System",
     "fr" => "#Système",
     "ja" => "#システム",
     "ru" => "#Система",
     "zh" => "#星系"},
   "portionSize" => 1_i64,
   "published" => false},
 2_i64 =>
  {"groupID" => 2_i64,
   "name" =>
    {"de" => "Corporation",
     "en" => "Corporation",
     "fr" => "Corporation",
     "ja" => "コーポレーション",
     "ru" => "Corporation",
     "zh" => "军团"},
   "portionSize" => 1_i64,
   "published" => false},
 3_i64 =>
  {"groupID" => 3_i64,
   "name" =>
    {"de" => "Region",
     "en" => "Region",
     "fr" => "Région",
     "ja" => "リージョン",
     "ru" => "Region",
     "zh" => "星域"},
   "portionSize" => 1_i64,
   "published" => false,
   "volume" => 1.0}}
@bew
Copy link
Contributor

bew commented Jun 3, 2018

This is resolved in master, and will be available in next release

@jhass jhass closed this as completed Jun 3, 2018
@straight-shoota
Copy link
Member

For reference: #5774

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

4 participants