Success comparison in DataSource is wrong #3

Open
tilmanpotthof opened this Issue Mar 6, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@tilmanpotthof

The comparison to check the success-attribute of the backObj is true if the server returns an empty-string. In consequence the success-attribute is undefined and the success-function will be called.

if (backObj.success == 'false')


'false' == 'false'   // true
undefined == 'false' // false

// same behavior for these values
'' == 'false'        // false
false == 'false'     // false
@ffzhuang

This comment has been minimized.

Show comment Hide comment
@ffzhuang

ffzhuang Mar 6, 2012

Owner

Will check this soon

Owner

ffzhuang commented Mar 6, 2012

Will check this soon

@tilmanpotthof

This comment has been minimized.

Show comment Hide comment
@tilmanpotthof

tilmanpotthof Mar 6, 2012

Reproduction steps (example)

• For the controller-method with the URL /calendarEvent/createEditEvent return an empty string instead of the json response.

Result

• No error message is displayed.

Solution

if (backObj.success === 'false' || Boolean(backObj.success) === false) {

== should be avoided as type coercion can be very confusing: http://javascript.crockford.com/code.html

Boolean(x) // is false for falsy values: '', undefined, null, 0, [], {}

Reproduction steps (example)

• For the controller-method with the URL /calendarEvent/createEditEvent return an empty string instead of the json response.

Result

• No error message is displayed.

Solution

if (backObj.success === 'false' || Boolean(backObj.success) === false) {

== should be avoided as type coercion can be very confusing: http://javascript.crockford.com/code.html

Boolean(x) // is false for falsy values: '', undefined, null, 0, [], {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment