ruby / ruby/psych

Can't deserialize a string that looks like a float properly

Open
#144 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
597
Forks
223
Avg merge
11h 23m
Merged PRs (30d)
3

Description

Under Syck if you register a domain type, the block will get the tag name and the value yielded to it as they are in the actual raw YAML.

In Psych however the value string has already been tokenized by the call at the bottom of Psych::Visitors::ToRuby#deserialize, before #accept is called.

This is a problem because if your serialized value string happens to look like a floating point number, then it will get parsed as a Float and your deserializer won't be able to get the original string so that it can parse it properly (without float's precision problems).

Is there another way to add domain class parsing in a way that won't get tokenized? It seems that at the moment we have to extend the big case statement in #deserialize (or use alias_method_chain to add a special case).

If not could we maybe rearrange slightly so that #tokenize is not called before #accept?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Psych::Visitors::ToRuby#deserialize and trace how #tokenize runs before #accept for registered domain types. Determine how deserialization can preserve the raw string for domain parsing without float conversion; done means the domain deserializer receives the original value and no precision is lost.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.