Skip to content

BREAKING(ini): parse understands booleans, undefined, null and numbers #6121

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

Merged
merged 5 commits into from
Nov 6, 2024

Conversation

WasixXD
Copy link
Contributor

@WasixXD WasixXD commented Oct 16, 2024

Closes #4806

@WasixXD WasixXD requested a review from kt3k as a code owner October 16, 2024 16:30
@CLAassistant
Copy link

CLAassistant commented Oct 16, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the ini label Oct 16, 2024
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.48%. Comparing base (45be5d3) to head (915ec94).
Report is 29 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6121      +/-   ##
==========================================
- Coverage   96.57%   96.48%   -0.10%     
==========================================
  Files         535      538       +3     
  Lines       40583    40974     +391     
  Branches     6094     6165      +71     
==========================================
+ Hits        39195    39534     +339     
- Misses       1344     1396      +52     
  Partials       44       44              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

ini/_ini_map.ts Outdated
: (_key, value, _section) => value;
: (_key, value, _section) => {
if (value === "undefined") return undefined;
if (!isNaN(+value) && !value.includes('"')) return parseInt(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use !isNaN(value)?

Copy link
Contributor Author

@WasixXD WasixXD Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no particular reason, I just put it that way out of habit
Edit: I just checked and isNaN expects a number, so there's no way to use !isNaN(value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows expression like 1e3 as parsed as number, and it results 1. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all, but its because the parseInt function just returns the first complete integer that it finds on the string. So IsNaN says that value is a number but parseInt can just parse the 1, but easy fix

Copy link
Contributor

@babiabeo babiabeo Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: I just checked and isNaN expects a number, so there's no way to use !isNaN(value)

Oh you're right. I forgot we're using typescript not javascript lol

Edit: BTW I'm curious about the check !value.includes('"'). What is it used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its a number but has a " the user wants as a string and not as a number

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

@kt3k
Copy link
Member

kt3k commented Oct 28, 2024

Can you also work on stringify?

@WasixXD
Copy link
Contributor Author

WasixXD commented Oct 28, 2024

yeah sure no problem

@kt3k kt3k changed the title feat(ini): parse understands booleans, undefined, null and numbers BREAKING(ini): parse understands booleans, undefined, null and numbers Oct 29, 2024
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these value interpretations are fine because they are very natural in JavaScript, and I guess they probably gave least surprise to the users. LGTM

Note: There's no official specifications for INI format, and major parsers are very incompatible with each other. So we need to choose one way of parsing them, and I find this one is enough reasonable.

@iuioiua
Copy link
Contributor

iuioiua commented Oct 29, 2024

AFAIK, this functionality is all that remains for stabilising ini.

@kt3k
Copy link
Member

kt3k commented Nov 5, 2024

Discussed this internally and we'd like to drop the interpretation of undefined literal as there's no other known parsers which parse "undefined" to undefined. (I pushed the commit 915ec94 to this branch)

What do you think?

@WasixXD
Copy link
Contributor Author

WasixXD commented Nov 5, 2024

thats ok, this comes closer to what JSON.parse do

@kt3k
Copy link
Member

kt3k commented Nov 6, 2024

Ok. Let's go with this

@kt3k kt3k merged commit bc20dbe into denoland:main Nov 6, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ini file parsing considers all values as strings
5 participants