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

feat: return empty object if string is empty #10

Closed
wants to merge 1 commit into from

Conversation

tobiasdiez
Copy link
Contributor

Without the special handling it doesn't pass this check

if (!JsonSigRx.test(val)) {
    return val
}

and thus returns an empty string again.

@pi0
Copy link
Member

pi0 commented Oct 19, 2022

Should be handled with #11 on strict mode

@pi0 pi0 closed this Oct 19, 2022
@tobiasdiez
Copy link
Contributor Author

I don't quite understand. Isn't the mapping of an empty string to an empty object what you would expect. This should also be independent of the strict mode, since the empty string is a valid json string and strict mode should only concern what happens if the string is not valid json. In fact, without this PR an empty string would throw an exception in the strict mode, which is not what you want either.

@pi0
Copy link
Member

pi0 commented Oct 19, 2022

Node.js behavior with JSON.parse(''): (same as strict mode)

> JSON.parse('')
Uncaught SyntaxError: Unexpected end of JSON input

Without strict mode, destr, returns values as-is if they are not detected as JSON. And returning empty string as is, also makes sense i think with this considration.

@tobiasdiez
Copy link
Contributor Author

Okay, thanks for the clarification!

@tobiasdiez tobiasdiez deleted the patch-1 branch October 19, 2022 09:58
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.

None yet

2 participants