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

Added support for constructorAction #4

Merged
merged 14 commits into from
Oct 23, 2019
Merged

Added support for constructorAction #4

merged 14 commits into from
Oct 23, 2019

Conversation

delvedor
Copy link
Member

As titled.
Now the following code is supported as well:

t.deepEqual(
  j.parse(
    '{"a": 5, "b": 6, "constructor":{"prototype":{"bar":"baz"}}, "__proto__": { "x": 7 } }',
      { protoAction: 'remove', constructorAction: 'remove' }
  ),
  { a: 5, b: 6 }
)

cc @watson

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM.

@delvedor
Copy link
Member Author

@mcollina I fear this should be considered a breaking change since the default constructorAction behavior is error. What do you think?

@mcollina
Copy link
Member

Is there any possibility that valid code could break because of this change?

Copy link
Contributor

@watson watson left a comment

Choose a reason for hiding this comment

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

I left a few nit review comments which aren't technically related to this PR, but since it contains a lot of style changes and refactorings anyway, I thought I might as well 😄

Beside those review comments, there was a few lines I couldn't make comments on which I just wrote here instead:

Line 9 in index.js:

-    if (reviver != null && typeof reviver === 'object') {
+    if (reviver !== null && typeof reviver === 'object') {

Line 29 in index.js:

-  if (!obj || typeof obj !== 'object') {
+  if (obj === null || typeof obj !== 'object') {

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
test.js Show resolved Hide resolved
@watson
Copy link
Contributor

watson commented Oct 23, 2019

@mcollina I guess you can't rule out that someone has a legitimate use for parsing {"constructor":...} 🤷‍♂

@delvedor
Copy link
Member Author

@mcollina yes, in the following case for example:

// old behavior
j.parse(
  '{"a": 5, "b": 6, "constructor":{"prototype":{"bar":"baz"}}, "__proto__": { "x": 7 } }',
  { protoAction: 'remove' }
) // => { a: 5: b:6, constructor: { prototype: { bar: 'baz' } } }

// new bahavior
j.parse(
  '{"a": 5, "b": 6, "constructor":{"prototype":{"bar":"baz"}}, "__proto__": { "x": 7 } }',
  { protoAction: 'remove' }
) // => SyntaxError

// for having the same behavior as before:
j.parse(
  '{"a": 5, "b": 6, "constructor":{"prototype":{"bar":"baz"}}, "__proto__": { "x": 7 } }',
  { protoAction: 'remove', constructorAction: 'ignore' }
) // => { a: 5: b:6, constructor: { prototype: { bar: 'baz' } } }

@mcollina
Copy link
Member

I would do a 2 stage release, where we ship the new option with the ignore flag, and then we flip the default in a major.

delvedor and others added 10 commits October 23, 2019 10:37
Co-Authored-By: Thomas Watson <w@tson.dk>
Co-Authored-By: Thomas Watson <w@tson.dk>
Co-Authored-By: Thomas Watson <w@tson.dk>
Co-Authored-By: Thomas Watson <w@tson.dk>
Co-Authored-By: Thomas Watson <w@tson.dk>
Co-Authored-By: Thomas Watson <w@tson.dk>
@watson
Copy link
Contributor

watson commented Oct 23, 2019

@mcollina unless you want to release some other features or fixes in this major, you might as well bump the major as this feature will not benefit anybody unless the user turns it on - in which case they might as well upgrade to the next major. So there's no real value in doing the gymnastics of releasing this in a non-breaking way under the current major. At least that's how I would probably do it 🤷‍♂

@delvedor
Copy link
Member Author

Yes, I agree with @watson, we are not planning any other major feature, and in case of a bug, we can release a fix anytime.
Regarding the usage in Fastify itself, we can update the library in the next major, or use the ignore setting in the current release line.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@delvedor delvedor merged commit 16c5efe into master Oct 23, 2019
@delvedor delvedor deleted the constructor-action branch October 23, 2019 16:15
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.

3 participants