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

Return null value from JSON.Parse #1904

Merged
merged 12 commits into from
Aug 31, 2016
Merged

Return null value from JSON.Parse #1904

merged 12 commits into from
Aug 31, 2016

Conversation

danmarshall
Copy link
Contributor

JSON.parse('') will throw a syntax error (in any browser). Fix is to return a null value. I saw this when my server returned HTTP 204 No Content.

JSON.parse('') will throw a syntax error (in any browser). Fix is to return a null value. I saw this when my server returned HTTP 204 No Content.
@kwonoj
Copy link
Member

kwonoj commented Aug 24, 2016

Would you add test cases for this change as well?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.115% when pulling 179fd73 on danmarshall:patch-1 into 80b817f on ReactiveX:master.

@danmarshall
Copy link
Contributor Author

Where do you add your tests?

@kwonoj
Copy link
Member

kwonoj commented Aug 24, 2016

I believe ajax-spec is place to go.

@danmarshall
Copy link
Contributor Author

Hi @kwonoj - I cloned locally and tried doing a build, to get myself familiar with the test runner. At some point it failed when it tried to run java (which I don't have) so I think the level of setup is greater than the code contribution... what do you think?

@kwonoj
Copy link
Member

kwonoj commented Aug 24, 2016

Jre is only needed to generate global build so you can safely ignore if you do not like to install jre. Just build / test would be sufficient for general workflow such as npm run build_test. You may able to check npm run info for other tasks available.

@danmarshall
Copy link
Contributor Author

@kwonoj do you have a test for your original fix that I can use as an example?

@kwonoj
Copy link
Member

kwonoj commented Aug 25, 2016

No, I just noticed I skipped test cases and just verified manually. Seems that's reason I wasn't able to caught issue, test didn't cover it.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.115% when pulling 3669375 on danmarshall:patch-1 into 80b817f on ReactiveX:master.

unit test for IE
added missing semicolon.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.115% when pulling 0d1d347 on danmarshall:patch-1 into 80b817f on ReactiveX:master.

@danmarshall
Copy link
Contributor Author

I verified that this unit test fails on the master branch without the fix, passes on this branch with the fix.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.115% when pulling fe61805 on danmarshall:patch-1 into 7b23e88 on ReactiveX:master.

@danmarshall
Copy link
Contributor Author

Hi @kwonoj would you mind taking a look at this? I spent a good deal of time yesterday writing the unit test, wanted to make sure that my additions are compatible with your framework style standards.

@kwonoj
Copy link
Member

kwonoj commented Aug 26, 2016

Sure, please allow me some time as I'll be offline for some time. I've brifely looked changes, interested if it's possible to remove mock for IE only - but that'll need some trial on my end.

@danmarshall
Copy link
Contributor Author

Mocking {x} is the way to test {x}, so mocking IE would be the way to test IE :)

@kwonoj
Copy link
Member

kwonoj commented Aug 26, 2016

That I agree completely, just about high level approach. I'll comment in detail soon as I promised.

@@ -396,7 +396,7 @@ export class AjaxResponse {
case 'json':
if ('response' in xhr) {
//IE does not support json as responseType, parse it internally
this.response = xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || '');
this.response = xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || 'null');
} else {
this.response = JSON.parse(xhr.responseText || '');
Copy link
Member

Choose a reason for hiding this comment

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

isn't this JSON.parse(xhr.responseText || ''); also need to be updated to 'null' for fallback string? this isn't directly related to IE, but still seems possible unexpected failure cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean on line 401 ? I did not exercise that code path, but I suppose that yes it should.

Copy link
Member

Choose a reason for hiding this comment

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

yes, 401. I know it's not directly related (for execution path to IE), but seems need to be updated as well.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.115% when pulling 6d87eb5 on danmarshall:patch-1 into 7b23e88 on ReactiveX:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.115% when pulling 3c661b5 on danmarshall:patch-1 into cb40e92 on ReactiveX:master.


export class MockXMLHttpRequestInternetExplorer extends MockXMLHttpRequest {
constructor() {
Copy link
Member

Choose a reason for hiding this comment

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

you can skip ctor if it doesn't do specific thing in inherited.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.115% when pulling f3b08c1 on danmarshall:patch-1 into cb40e92 on ReactiveX:master.

@kwonoj
Copy link
Member

kwonoj commented Aug 30, 2016

LGTM, I'll leave this PR around couple of days to see if other suggestions around before check in.

@jayphelps
Copy link
Member

LGTM, needs rebase plz and while you're add it please squash as a single commit using our commit message format (see existing commits for reference)

For others reference, the behavior of having it be xhr.response = null is per spec when responseType === 'json'

https://xhr.spec.whatwg.org/#json-response

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.115% when pulling 691dd2e on danmarshall:patch-1 into 990594b on ReactiveX:master.

JSON.parse('') will throw a syntax error (in any browser). Fix is to return a null value.
This happens during an HTTP 204 'No Content' in IE.
Added a mock for InternetExplorer. Added unit tests for HTTP 204.

closes #1381
@coveralls
Copy link

coveralls commented Aug 31, 2016

Coverage Status

Coverage remained the same at 97.115% when pulling fe61805 on danmarshall:patch-1 into 7b23e88 on ReactiveX:master.

@jayphelps jayphelps merged commit 6ba374e into ReactiveX:master Aug 31, 2016
@jayphelps
Copy link
Member

jayphelps commented Aug 31, 2016

@danmarshall I went ahead and squashed it. Check out http://push.cwcon.org/learn/squashing-commits.html for further info about how to squash your commits into a one for future PRs. 💃

Thanks for your fix!

@danmarshall
Copy link
Contributor Author

Awesome! When is your next publish to NPM ?

@jayphelps
Copy link
Member

@danmarshall the next beta release isn't set. There are usually a release at least once a month, so we're due for one shortly I imagine. It's up to @Blesh

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants