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

Fixes #1457, int val output in TOML format, adds test #1458

Merged
merged 6 commits into from
Jun 26, 2018

Conversation

slathrop
Copy link
Contributor

- Summary
Fixes #1457, int val output in TOML format, adds test

- Test plan
Test added and passing for int and float

- Description for the changelog
Fix int val output in TOML format file

@verythorough
Copy link
Contributor

verythorough commented Jun 20, 2018

Deploy preview for cms-demo ready!

Built with commit 7b877e0

https://deploy-preview-1458--cms-demo.netlify.com

@verythorough
Copy link
Contributor

verythorough commented Jun 20, 2018

Deploy preview for netlify-cms-www ready!

Built with commit 7b877e0

https://deploy-preview-1458--netlify-cms-www.netlify.com

@@ -192,7 +192,7 @@ describe('Frontmatter', () => {
);
});

it('should stringify YAML with --- delimiters when it is explicitly set as the format without a custom delimiter',
Copy link
Contributor

Choose a reason for hiding this comment

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

If this file doesn't have any actual code changes, can we just clean up the diff?

@@ -4,13 +4,19 @@ import moment from 'moment';
import AssetProxy from 'ValueObjects/AssetProxy';
import { sortKeys } from './helpers';

// IE polyfill for Number.isInteger
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't actually support IE, so this can be removed. 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Docs refer to IE11 here. Couldn't find any other references to browser support in docs though.

...Will remove this polyfill shortly though, as I can confirm that the CMS won't load at all in IE11 right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...BTW, I did find the discussion in issues here RE: browser support, with a summary at the end. 😃

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, feel free to PR a removal for that if you want.

cc/ @verythorough

const outputReplacer = (key, value) => {
if (moment.isMoment(value)) {
return value.format(value._f);
}
if (value instanceof AssetProxy) {
return `${ value.path }`;
}
if (Number.isInteger(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should be checking isSafeInteger instead, so we don't accidentally output an invalid number? Or is that only a concern for computations and it shouldn't be a problem with toString()? That was the original problem that @iology noted for tomlify anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think isInteger is sufficient... we already know we aren't dealing with a string representation of an int-like number that could overflow or lose precision. We're dealing with a straight-up number that JavaScript believes to be an int. And right, no calculations here. We're just telling tomlify not to put decimal places on the thing, which we must do by giving it a string representation of what we want rendered in the TOML file.

@tech4him1
Copy link
Contributor

I think isInteger is sufficient... we already know we aren't dealing with a string representation of an int-like number that could overflow or lose precision. We're dealing with a straight-up number that JavaScript believes to be an int. And right, no calculations here. We're just telling tomlify not to put decimal places on the thing, which we must do by giving it a string representation of what we want rendered in the TOML file.

That was my original thought as well. I just wasn't sure if it was relevant because obviously the creator of tomlify did?

@jakwings
Copy link

Hi, I'm the author of "tomlify". Tomlify, which is schema-less, does not distinguish between floats and integer, and it only throw an error when the number is not finite. So if you need exact integers, you should examine the key paths and check the numbers with Number.isSafeInteger and take care of overflow and underflow in other code.

@slathrop
Copy link
Contributor Author

OK, so @tech4him1, I understand the points made RE: isSafeInteger, but really the CMS is just in the role of serializing to a TOML file here based on what is handed to it. The CMS's job isn't to "check the math" so-to-speak. Are you satisfied with this bug-fix PR as-is now?

@tech4him1
Copy link
Contributor

Yes, thank you for your time answering my questions. 😄

Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

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

Thanks!

@erquhart erquhart merged commit 5a93f04 into decaporg:v1 Jun 26, 2018
erquhart pushed a commit to erquhart/netlify-cms that referenced this pull request Jun 26, 2018
@tech4him1
Copy link
Contributor

@slathrop By the way, I'm sorry if I came across as argumentative -- I really appreciate you taking the time to submit this PR. I just wanted to make sure I fully understood it since there was potential for problems. Thanks!

@slathrop
Copy link
Contributor Author

@tech4him1 Not at all, but very thoughtful of you to consider it anyway. Thanks.

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 this pull request may close these issues.

5 participants