Bug in the Wikipedia main web page

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in the Wikipedia main web page

Sukyoung Ryu
Dear all,

We are researchers at KAIST in Korea working on finding JavaScript bugs in web pages.  While analyzing top websites from Alexa.com, we found an issue, which seems to be a bug, on the Wikipedia main web page (wikipedia.org).  We would be grateful if you can either confirm that it is a bug and even better fix it or let us know what we're missing.

Here's the issue.  When a user selects a language in which search results are displayed via the language selection button from the Wikipedia main web page, the following JavaScript function is executed:

 1     function setLang(lang) {
 2         var uiLang = navigator.language || navigator.userLanguage, date = new Date();
 3
 4         if (uiLang.match(/^\w+/) === lang) {
 5             date.setTime(date.getTime() - 1);
 6         } else {
 7            date.setFullYear(date.getFullYear() + 1);
 8         }
 9
10       document.cookie = "searchLang=" + lang +  ";expires=" + date.toUTCString() +  ";domain=" + location.host + ";";
11   }

Depending on the evaluation result of the conditional expression on line 4, "uiLang.match(/^\w+/) === lang", the function leaves or dose not leave the selected language information on  the user's computer through a cookie.  But we found that the expression, "uiLang.match(/^\w+/) === lang", always evaluates to false, which results in that the function always leaves cookies on users' computers.  We think that changing the contidional expression, "uiLang.match(/^\w+/) === lang", to the expression, "uiLang.match(/^\w+/) == lang", will solve the problem.

This problem may occur in the main web pages of all the Wikimedia sites.  Could you kindly let us know what you think?  Thank you in advance.

Best,
Changhee Park and Sukyoung Ryu


_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Bug in the Wikipedia main web page

Yair Rand
Thank you for pointing out this bug. Your suggested change to
MediaWiki:Gadget-wm-portal.js has been implemented by Meta-Wiki
administrator User:PiRSquared17.


On Tue, Jan 28, 2014 at 6:50 PM, Sukyoung Ryu <[hidden email]>wrote:

> Dear all,
>
> We are researchers at KAIST in Korea working on finding JavaScript bugs in
> web pages.  While analyzing top websites from Alexa.com, we found an issue,
> which seems to be a bug, on the Wikipedia main web page (wikipedia.org).
>  We would be grateful if you can either confirm that it is a bug and even
> better fix it or let us know what we're missing.
>
> Here's the issue.  When a user selects a language in which search results
> are displayed via the language selection button from the Wikipedia main web
> page, the following JavaScript function is executed:
>
>  1     function setLang(lang) {
>  2         var uiLang = navigator.language || navigator.userLanguage, date
> = new Date();
>  3
>  4         if (uiLang.match(/^\w+/) === lang) {
>  5             date.setTime(date.getTime() - 1);
>  6         } else {
>  7            date.setFullYear(date.getFullYear() + 1);
>  8         }
>  9
> 10       document.cookie = "searchLang=" + lang +  ";expires=" +
> date.toUTCString() +  ";domain=" + location.host + ";";
> 11   }
>
> Depending on the evaluation result of the conditional expression on line
> 4, "uiLang.match(/^\w+/) === lang", the function leaves or dose not leave
> the selected language information on  the user's computer through a cookie.
>  But we found that the expression, "uiLang.match(/^\w+/) === lang", always
> evaluates to false, which results in that the function always leaves
> cookies on users' computers.  We think that changing the contidional
> expression, "uiLang.match(/^\w+/) === lang", to the expression,
> "uiLang.match(/^\w+/) == lang", will solve the problem.
>
> This problem may occur in the main web pages of all the Wikimedia sites.
>  Could you kindly let us know what you think?  Thank you in advance.
>
> Best,
> Changhee Park and Sukyoung Ryu
>
>
> _______________________________________________
> Wikitech-l mailing list
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Bug in the Wikipedia main web page

Sukyoung Ryu
Thank you for the quick fix!

Best,
--
Sukyoung


On Jan 29, 2014, at 9:55 AM, Nathan wrote:

> FYI in case you aren't subscribed to the list.
>
> ---------- Forwarded message ----------
> From: Yair Rand <[hidden email]>
> Date: Tue, Jan 28, 2014 at 7:25 PM
> Subject: Re: [Wikitech-l] Bug in the Wikipedia main web page
> To: Wikimedia developers <[hidden email]>
>
>
> Thank you for pointing out this bug. Your suggested change to
> MediaWiki:Gadget-wm-portal.js has been implemented by Meta-Wiki
> administrator User:PiRSquared17.
>
>
> On Tue, Jan 28, 2014 at 6:50 PM, Sukyoung Ryu <[hidden email]>wrote:
>
> > Dear all,
> >
> > We are researchers at KAIST in Korea working on finding JavaScript bugs in
> > web pages.  While analyzing top websites from Alexa.com, we found an issue,
> > which seems to be a bug, on the Wikipedia main web page (wikipedia.org).
> >  We would be grateful if you can either confirm that it is a bug and even
> > better fix it or let us know what we're missing.
> >
> > Here's the issue.  When a user selects a language in which search results
> > are displayed via the language selection button from the Wikipedia main web
> > page, the following JavaScript function is executed:
> >
> >  1     function setLang(lang) {
> >  2         var uiLang = navigator.language || navigator.userLanguage, date
> > = new Date();
> >  3
> >  4         if (uiLang.match(/^\w+/) === lang) {
> >  5             date.setTime(date.getTime() - 1);
> >  6         } else {
> >  7            date.setFullYear(date.getFullYear() + 1);
> >  8         }
> >  9
> > 10       document.cookie = "searchLang=" + lang +  ";expires=" +
> > date.toUTCString() +  ";domain=" + location.host + ";";
> > 11   }
> >
> > Depending on the evaluation result of the conditional expression on line
> > 4, "uiLang.match(/^\w+/) === lang", the function leaves or dose not leave
> > the selected language information on  the user's computer through a cookie.
> >  But we found that the expression, "uiLang.match(/^\w+/) === lang", always
> > evaluates to false, which results in that the function always leaves
> > cookies on users' computers.  We think that changing the contidional
> > expression, "uiLang.match(/^\w+/) === lang", to the expression,
> > "uiLang.match(/^\w+/) == lang", will solve the problem.
> >
> > This problem may occur in the main web pages of all the Wikimedia sites.
> >  Could you kindly let us know what you think?  Thank you in advance.
> >
> > Best,
> > Changhee Park and Sukyoung Ryu
> >
> >
> > _______________________________________________
> > Wikitech-l mailing list
> > [hidden email]
> > https://lists.wikimedia.org/mailman/listinfo/wikitech-l
> _______________________________________________
> Wikitech-l mailing list
> [hidden email]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>


_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Bug in the Wikipedia main web page

Sukyoung Ryu
We've noticed that a bug we reported on Jan 28, 2014 and got fixed right away as follows:

http://meta.wikimedia.org/w/index.php?title=MediaWiki%3AGadget-wm-portal.js&type=revision&diff=7268382&oldid=7164177

revived recently as follows:

http://meta.wikimedia.org/w/index.php?title=MediaWiki%3AGadget-wm-portal.js&type=revision&diff=10643039&oldid=10643032

Could you kindly let us know the reason?

Best,
--
Sukyoung


On Jan 29, 2014, at 11:26 AM, Sukyoung Ryu wrote:

> Thank you for the quick fix!
>
> Best,
> --
> Sukyoung
>
>
> On Jan 29, 2014, at 9:55 AM, Nathan wrote:
>
>> FYI in case you aren't subscribed to the list.
>>
>> ---------- Forwarded message ----------
>> From: Yair Rand <[hidden email]>
>> Date: Tue, Jan 28, 2014 at 7:25 PM
>> Subject: Re: [Wikitech-l] Bug in the Wikipedia main web page
>> To: Wikimedia developers <[hidden email]>
>>
>>
>> Thank you for pointing out this bug. Your suggested change to
>> MediaWiki:Gadget-wm-portal.js has been implemented by Meta-Wiki
>> administrator User:PiRSquared17.
>>
>>
>> On Tue, Jan 28, 2014 at 6:50 PM, Sukyoung Ryu <[hidden email]>wrote:
>>
>>> Dear all,
>>>
>>> We are researchers at KAIST in Korea working on finding JavaScript bugs in
>>> web pages.  While analyzing top websites from Alexa.com, we found an issue,
>>> which seems to be a bug, on the Wikipedia main web page (wikipedia.org).
>>> We would be grateful if you can either confirm that it is a bug and even
>>> better fix it or let us know what we're missing.
>>>
>>> Here's the issue.  When a user selects a language in which search results
>>> are displayed via the language selection button from the Wikipedia main web
>>> page, the following JavaScript function is executed:
>>>
>>> 1     function setLang(lang) {
>>> 2         var uiLang = navigator.language || navigator.userLanguage, date
>>> = new Date();
>>> 3
>>> 4         if (uiLang.match(/^\w+/) === lang) {
>>> 5             date.setTime(date.getTime() - 1);
>>> 6         } else {
>>> 7            date.setFullYear(date.getFullYear() + 1);
>>> 8         }
>>> 9
>>> 10       document.cookie = "searchLang=" + lang +  ";expires=" +
>>> date.toUTCString() +  ";domain=" + location.host + ";";
>>> 11   }
>>>
>>> Depending on the evaluation result of the conditional expression on line
>>> 4, "uiLang.match(/^\w+/) === lang", the function leaves or dose not leave
>>> the selected language information on  the user's computer through a cookie.
>>> But we found that the expression, "uiLang.match(/^\w+/) === lang", always
>>> evaluates to false, which results in that the function always leaves
>>> cookies on users' computers.  We think that changing the contidional
>>> expression, "uiLang.match(/^\w+/) === lang", to the expression,
>>> "uiLang.match(/^\w+/) == lang", will solve the problem.
>>>
>>> This problem may occur in the main web pages of all the Wikimedia sites.
>>> Could you kindly let us know what you think?  Thank you in advance.
>>>
>>> Best,
>>> Changhee Park and Sukyoung Ryu
>>>
>>>
>>> _______________________________________________
>>> Wikitech-l mailing list
>>> [hidden email]
>>> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>> _______________________________________________
>> Wikitech-l mailing list
>> [hidden email]
>> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>>
>


_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Bug in the Wikipedia main web page

Jeremy Baron
On May 12, 2015 8:05 AM, "Sukyoung Ryu" <[hidden email]> wrote:
> Could you kindly let us know the reason?

Please leave your comments and questions at
https://meta.wikimedia.org/wiki/MediaWiki_talk:Gadget-wm-portal.js

Thanks

-Jeremy
_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Reply | Threaded
Open this post in threaded view
|

Re: Bug in the Wikipedia main web page

Minh Nguyen-6
In reply to this post by Sukyoung Ryu
On 2015-05-12 05:05, Sukyoung Ryu wrote:
> We've noticed that a bug we reported on Jan 28, 2014 and got fixed right away as follows:
>
> http://meta.wikimedia.org/w/index.php?title=MediaWiki%3AGadget-wm-portal.js&type=revision&diff=7268382&oldid=7164177
>
> revived recently as follows:
>
> http://meta.wikimedia.org/w/index.php?title=MediaWiki%3AGadget-wm-portal.js&type=revision&diff=10643039&oldid=10643032
>
> Could you kindly let us know the reason?

Hi Sukyoung,

Since the fix was originally put in, we made an effort to clean up the
page's JavaScript code in part using the JSHint tool. [1] JSHint flags
uses of JavaScript's == operator, suggesting === instead. I blindly
followed that suggestion without noticing that the left-hand expression
was a call to String.prototype.match(), which either returns null or an
array.

It turns out the former code had been working because ['foo'] == 'foo'
in JavaScript. I've been coding in JavaScript for years and was totally
unaware of that behavior -- more reason to use === instead of ==. I
fixed the code in a way that is unlikely to regress in the future.

Thank you for re-reporting the bug! Please report any future bugs you
find to the portals' talk page [2].

[1] http://jshint.com/
[2] https://meta.wikimedia.org/wiki/Talk:Project_portals

--
Minh Nguyen <[hidden email]>
Jabber: [hidden email]; Blog: http://notes.1ec5.org/


_______________________________________________
Wikitech-l mailing list
[hidden email]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l