Hello developers,

I found an error in example code from Nokia. The code is used in several example projects, and it is in the code for reading a feed.
It is for example in the news reader example, in the file "jquery.jfeed.js"

I think the bug will cause that the feed reader does not accept gif as media, but instead other types.

Look at this:


Code:
if(media.length > 0 && jQuery.inArray(media.eq(0).attr('type'), ['image/gif', 'image/jpeg', 'image/jpg', 'image/png'])) {
...
}

Problem is that the jQuery-Method inArray() returns -1 if not found. Otherwise it returns the index of the found element. So it returns 0 for "image/gif" and this evaluates to false.
See api.jquery.com/jQuery.inArray/

The $.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match. If the first element within the array matches value, $.inArray() returns 0.

Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), if we're checking for the presence of value within array, we need to check if it's not equal to (or greater than) -1.
So the code need to be corrected to

Code:
if(media.length > 0 && (jQuery.inArray(media.eq(0).attr('type'), ['image/gif', 'image/jpeg', 'image/jpg', 'image/png'])) > -1 ) {
Regards

Karsten Meier