Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13412 closed bug (duplicate)

parseJSON does not handle undefined in 1.9.1

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: ajax Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

parseJSON has been clearly changed from 1.8.3 to 1.9.1. I have verified that 1.8.3 still handles undefined and returns null which is aligned with the documentation. The new version throws "Uncaught SyntaxError: Unexpected token u"

Change History (12)

comment:1 Changed 10 years ago by dmethvin

Resolution: notabug
Status: newclosed

JSON.parse(undefined) *should* be an error since it is invalid JSON. The request for docs fix is here:

https://github.com/jquery/api.jquery.com/issues/243

comment:2 Changed 10 years ago by dmethvin

BTW, the jQuery Migrate plugin identifies this. Please use the jQuery Migrate plugin. If you'd like you can submit a pull request to clarify the docs.

comment:3 Changed 10 years ago by anonymous

I believe this is a poor decision, this is a case where purism creates an unnecessary burden. Plugins and javascript galore have relied on what is a documented behavior and this was not a bad thing. The validation check was in one centralized place. Now every bit of code by everyone else must do the check themselves.

I don't believe that the cost is worth it.

comment:4 Changed 10 years ago by anonymous

just saying

if (!form.valid()) {

alert("not valid"); return false;

}

will now fail with "Uncaught SyntaxError: Unexpected token u"

what is the correct way of writing the above then? as far as i knew that was correct.... now

jquery validate 1.11.0 needs to be updated...or is this part of jquery.validate.unobtrusive.js

comment:5 Changed 10 years ago by dmethvin

Both of those are plugins, you'd need to ask the plugin author. The jQuery Migrate 1.1.1 plugin should allow the code to work as-is.

comment:6 Changed 10 years ago by anonymous

Microsoft should not be writing plugins?? Kidding, they need to fix them though

comment:7 Changed 10 years ago by [email protected]

I also disagree with the decision to close this. I don't understand why it can't just do the 1.8.3 behavior.

Anonymous said it best: "I believe this is a poor decision, this is a case where purism creates an unnecessary burden." +1

comment:8 Changed 10 years ago by dmethvin

Please use the jQuery Migrate plugin until any dependent code is fixed, that's why we wrote it. Remediations in your own code should be only a line or two.

comment:9 Changed 10 years ago by anonymous

+1 for using the old behaviour, this is an unnecessary burden on me as a plugin user - especially since the plugin I have a problem with is not open source (nice one Microsoft). I also don't see why the old behaviour is problematic?

comment:10 Changed 10 years ago by Bobby Tables

Although I feel similar to most here in that the parseJSON method should probably do some simple checking on the input before attempting to parse the JSON, this is equally an issue caused by Microsoft haphazardly tossing whatever they want into the parser and expecting gold.

I've submitted a bug report to Microsoft for this issue; you can see it at: https://connect.microsoft.com/VisualStudio/feedback/details/786650/jquery-validate-unobtrusive-js-broken-for-jquery-1-9-and-above

Maybe they will get around to fixing it in my lifetime...

comment:11 Changed 10 years ago by gibson042

Resolution: notabug
Status: closedreopened

comment:12 Changed 10 years ago by gibson042

Component: unfiledajax
Resolution: duplicate
Status: reopenedclosed

Duplicate of #13169.

Note: See TracTickets for help on using tickets.