-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
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.
Would you add test cases for this change as well? |
Where do you add your tests? |
I believe |
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? |
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 |
@kwonoj do you have a test for your original fix that I can use as an example? |
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. |
unit test for IE
added missing semicolon.
I verified that this unit test fails on the master branch without the fix, passes on this branch with the fix. |
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. |
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. |
Mocking {x} is the way to test {x}, so mocking IE would be the way to test IE :) |
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 || ''); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
||
export class MockXMLHttpRequestInternetExplorer extends MockXMLHttpRequest { | ||
constructor() { |
There was a problem hiding this comment.
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.
LGTM, I'll leave this PR around couple of days to see if other suggestions around before check in. |
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 |
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
@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! |
Awesome! When is your next publish to NPM ? |
@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 |
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. |
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.