There is a problem with line 67 in file js/base.js

var pair = pairs[i].split('=');

variable pairs[i] sometimes contain functions and under Chrome appear fatal error, so I dont` how come functions can be in this array but I`ve fixed code into

if(typeof(pairs[i]) == 'string'){
var pair = pairs[i].split('=');
// Ignore the 'q' path argument, if present.
if (pair[0] != 'q' && pair[1]) {
args[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
}
} else if (typeof(pairs[i]) == 'function') {
eval(pairs[i]);
}

And now it works fine.

Is there anybody who also saw error like this? This problem appeared after I`ve updated views to latest version (2.10)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikedance’s picture

I am receiving this error as well, luckily I found this issue!

dawehner’s picture

Could you please make a real patch out of it?

migueltrindade’s picture

Same problem with IE8 / IE7, but this work for me.

Thanks man!!!!

Here is my new Helper Function:

Drupal.Views.parseQueryString = function (query) {
  var args = {};
  var pos = query.indexOf('?');
  if (pos != -1) {
    query = query.substring(pos + 1);
  }
  var pairs = query.split('&');
  for(var i in pairs) {
    /*var pair = pairs[i].split('=');
    // Ignore the 'q' path argument, if present.
    if (pair[0] != 'q' && pair[1]) {
      args[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
    }*/
		if(typeof(pairs[i]) == 'string'){
			var pair = pairs[i].split('=');
			// Ignore the 'q' path argument, if present.
			if (pair[0] != 'q' && pair[1]) {
				args[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
			}
		} else if (typeof(pairs[i]) == 'function') {
			eval(pairs[i]);
		}
  }
  return args;
};

[]´s

setvik’s picture

Status: Active » Needs review
FileSize
755 bytes

Attached is a patch of the above slightly reworked to only look at elements of pairs[i] that are of type 'string'.

manderson725’s picture

I'm a little too green with drupal. I'm having this same issue I believe. Could someone give me a clue how to apply this patch? I get that it goes in the views/base.js file, but which line, etc. Thank you :)

Nevermind, i see where to do it..and i'll have to figure out how to get into core files to do so.

manderson725’s picture

As it turns out the error I get which is just like this one is because i'm using twitter widget code in a module. it is conflicting with drupal views javascript. Does anyone know if this patch will correct that conflict? Is anyone above also experiencing this along with a twitter widget?

vadim.eremeev’s picture

Thanks for patch, guys!

@manderson725: yes, you right this bug maybe appear after I`ve installed twitter widget code, but thats quite interesting which conflicts can be there, gonna make analysis today

yang_yi_cn’s picture

Status: Needs review » Reviewed & tested by the community

#4 works for me

bibo’s picture

It seems there is a very similar issue with admin-module (admin.toolbar.js and twitter's widget.js = fatal error in Chrome, Safari and IE, but not Firefox or Safari).

It has been driving me nuts for a while.. but I guess this patch can be implemented for admin too.

I created an issue for that here: #797492: Toolbar won't open in Safari or Chrome. JS error in admin.toolbar.js

bibo’s picture

To fix the same error in admin-module, I just added:

	    if(typeof(query[i]) == 'string'){
			var values = query[i].split('=');
		}
Johnny vd Laar’s picture

patch seems to fix a bug on my project as well

t0b1’s picture

thanks :)

pharoz’s picture

Just confirming that applying the patch also resolved my problem in IE8. Under chrome and firefox, there was no issue.

In IE, I had 2 areas that had AJAX pagination on and when I clicked on the next item in either area, it would refresh the entire page including the other AJAX pagination area. After the patch, each area paginated correctly independent of the other section.

Gekiboy’s picture

setvik's patch is completely identical to a patch I made to resolve this issue. Since I came up with it independently, I think it's perfect :)

The issue is that for some reason the basic array object produced from calling the split function on a string has a function associated with it in some versions of IE. I'm not sure if this is a result of IE doing something weird or of another js library modifying the structure of the basic array object. Either way, the solution of checking each element to make sure it's a string before parsing it is effective and safe. It's a good solution until someone can get to the bottom of where the indexOf function is coming from.

dooug’s picture

I also independently created a similar patch. +1 for reviewed & tested. Hope to see this committed soon.

bleen’s picture

I have just tested the patch in #4 and it applied fine, and solved the problem I was having (described here: http://drupalbin.com/15283?nocache=1) with a function ending up as a "pair" causing a fatal error in webkit-based browsers.

RTBC++

bibo’s picture

I also independently created a similar patch. +1 for reviewed & tested. Hope to see this committed soon.

Hoping for a soonish commit too, since I hate patching important modules like views.

Even if the twitter-widget js is to blame for this incompatibilty, the problem is very avoidable. This small patch at #4 avoids JS conflicts without adding unnecessary complexity.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Ok, guess we can consider this one fixed.

merlinofchaos’s picture

Er. COmmitted to all branches.

ianivs’s picture

This fix works but I don't think it's the correct way to fix this.

The problem is the use of the for...in loop syntax, which loops over all properties of an object (except built-ins) and shouldn't really be used to iterate over arrays. For example, IE doesn't implement Array.indexOf so some javascript libraries may add an implementation to the Array prototype, which means that indexOf is now a user-defined property and will show up when using a for...in loop.

The proper fix is never to use this syntax to iterate over arrays, instead of

for (var in pairs)

you should use

for (var i=0; i < pairs.length; i++)

and you'll only iterate over the strings created by split.

dawehner’s picture

Why not even use:

$.each(pairs, function (var) {
});
ianivs’s picture

That's not the point :)

No need to bring jQuery into this when a for loop is perfectly fine. I'm just advocating the correct for loop synatx.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ChrisRut’s picture

Version: 6.x-2.10 » 6.x-2.x-dev
Status: Closed (fixed) » Active
FileSize
436 bytes
42.01 KB

I second the vote from ianivs #20, IE doesn't like this very much: http://drupal.org/files/issues/js-error_views.png

Proposed: http://drupal.org/files/issues/798764-views-base.js_.patch

-  for(var i in pairs) {
+  for (var i = 0; i < pairs.length; ++) {

Thanks also to stuartEngelhardt

ChrisRut’s picture

FileSize
626 bytes

Corrected patch (forgot the 'i'): http://drupal.org/files/issues/798764-2-views-base.js_.patch

-  for(var i in pairs) {
+  for (var i = 0; i < pairs.length; i++) {
jm.federico’s picture

FileSize
396 bytes

From #25
re-rolling against 6.x-2.11

jm.federico’s picture

Status: Active » Needs review

Changing status

acondiff’s picture

this is not working for me. =(

I did this and it says that there is an invalid argument in jquery.

Any ideas?

Web Assistant’s picture

I'm also getting the Invalid argument error in jquery.min.js (I'm using the jquery_update module if that makes any difference).

Just to update, this error wasn't related to the original problem, the patch worked for the initial error but my new problem was with using jquery ui.

jm.federico’s picture

@acondiff, @rolandcarney

Can you provide more info about the error you are getting? Patch works for me and more ppl, there must be another module doing funny things with your js. Is it happening in eery browser?

@rolandcarney
Please open a new issue with your problem is it is caused by a different module. Specially if the patch was working before, or provide more details on how it relates to this case.

acondiff’s picture

It is only in Internet Explorer. I also found it only throws the base.js error when the Shadowbox module is on. There must be some module causing your error because there is not an error in IE without this module on. There is probably a script or function that is causing this that is in several different modules.

After running the IE development tool it gave me the error that jQuery was undefined and it was caused by this line:

jQuery.extend(Drupal.settings, { "basePath": "/", "views": { "ajax_path": [ "/views/ajax", "/views/ajax" ], "ajaxViews": [ { "view_name": "home_posts", "view_display_id": "panel_pane_1", "view_args": "", "view_path": "front_page", "view_base_path": null, "view_dom_id": 7, "pager_element": 0 }, { "view_name": "home_district_standings", "view_display_id": "default", "view_args": "356", "view_path": "front_page", "view_base_path": null, "view_dom_id": 9, "pager_element": 0 } ] }, "beautytips": { "calendar-tooltips": { "cssStyles": [  ], "cssSelect": ".mini-day-on a", "contentSelector": "$(this).next().html()", "trigger": [ "mouseover", "mouseout" ], "list": [ "cssStyles", "contentSelector", "trigger" ] } } });

It is a line contained in a script tag that seems to be printed into my html page. It contains all of my views that use ajax ("home_posts" -uses ajax pager, and "home_district_standings" - uses ajax sorting). Any ideas?

jm.federico’s picture

@acondiff
Which patch did you apply? What version of views are you using?
Hard to tell what prob is. I suggest you open a new issue with support request, otherwise it might end up highjacking this issue, which seems resolved.

Cheers

acondiff’s picture

My new issue is created here: http://drupal.org/node/951494

Thanks.

jm.federico’s picture

Before reporting an error please make sure you apply patch from #798764-26: base.js line 67 chrome, variable pairs[i] sometimes contain functions and not only stings, the one in #4 breaks in IE.

Cheers

merlinofchaos’s picture

Status: Needs review » Closed (duplicate)

This patch is a dup of #514128: Use of 'for (i in my_array)' javascript array iteration causes issues when used with Prototype -- however, that patch broke things when it was committed and was reverted.

kingandy’s picture

Status: Closed (duplicate) » Patch (to be ported)

Sorry to revive old issues, but I don't believe this issue is a duplicate.

#514128 deals with use of the for(var x in y) structure. This issue is in the following line, which is trying to perform split() on a non-string. Nothing to do with the for loop.

Unless the "pairs" variable has been strongly ensured to only contain strings, this issue still exists in 6.x-2.12 and 6.x-3.0-alpha3.

Looks like it's been fixed in 7.x-3.0-beta3, with the if (typeof(pairs[i]) == 'string') { fix as presented in the patch in #4 (no else {eval(pairs[i])} clause). Therefore I'm guessing all this needs is to be rolled against the current version and committed.

Setting "to be ported" as the patch exists, and the code is in use in the D7 branch, but it doesn't look as though it'll work as is on the current release.

AaronBauman’s picture

Status: Patch (to be ported) » Fixed

This has been fixed in 2.x-dev and 3.x-dev using the typeof operator

kingandy’s picture

Ah, sweet, I didn't think to check dev. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Omar Alahmed’s picture

#25 worked perfectly for me, thanks ChrisRut

Ludo.R’s picture

Has this patch been commited?
I still have this issue in 6.x-2.12

Here's the function :

/**
 * Helper function to parse a querystring.
 */
Drupal.Views.parseQueryString = function (query) {
  var args = {};
  var pos = query.indexOf('?');
  if (pos != -1) {
    query = query.substring(pos + 1);
  }
  var pairs = query.split('&'); //line 67
  for(var i in pairs) {
    var pair = pairs[i].split('=');
    // Ignore the 'q' path argument, if present.
    if (pair[0] != 'q' && pair[1]) {
      args[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
    }
  }
  return args;
};

EDIT : sorry, I just realized my version was prior to this patch.