Skip to main content

Bug Tracker

Side navigation

#4498 closed feature (fixed)

Opened April 06, 2009 04:32PM UTC

Closed April 10, 2009 11:30PM UTC

unexpected redirect in jQuery.extend function

Reported by: oluckyman Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: extend Cc:
Blocked by: Blocking:
Description

i have post request:

$.post( this.loggerUrl, {url:this.url, action:action, timestamp:date.getTime()} )

where this.url == document.location

$.post -> $.ajax ->

s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));

and inside jQuery.extend we have line 604:

else if ( copy !== undefined)

target[ name ] = copy;

in this line we have redirect, when target == location and name == "href".

in my own script i'm fix it by replacing

$.post( this.loggerUrl, {url:this.url, action:action, timestamp:date.getTime()} )

to

$.post( this.loggerUrl, {url:this.url.toString(), action:action, timestamp:date.getTime()} )

but how about other users?

i spent one hour before found this feature -)


(sorry for my english)

Attachments (0)
Change History (3)

Changed April 07, 2009 12:34AM UTC by dmethvin comment:1

Wow, I'm sure that was a pain to diagnose. I can see why it is happening though. The

url
parameter should be a
String
:

http://docs.jquery.com/Ajax/jQuery.ajax#options

However,

document.location
is not a string. It's a Location object with properties like
.href
and methods like
.toString()

https://developer.mozilla.org/en/DOM/document.location

If you said

url: document.location.href
it should work fine.

Changed April 07, 2009 12:29PM UTC by oluckyman comment:2

Replying to [comment:1 dmethvin]:

Wow, I'm sure that was a pain to diagnose. I can see why it is happening though. The
url
parameter should be a
String
: http://docs.jquery.com/Ajax/jQuery.ajax#options However,
document.location
is not a string. It's a Location object with properties like
.href
and methods like
.toString()
https://developer.mozilla.org/en/DOM/document.location If you said
url: document.location.href
it should work fine.

Thanx for reply. I'm have fix it as you say.

BUT, I do not think, that this feature is good-) Maybe explicitly convert "key/value pairs" inside

jQuery.extend
function? Or describe this unexpected behaviour in documentation? with large letters and red color: "DEVELOPER! PLEASE, CONVERT READONLY OBJECTS TO STRING, BEFORE PASS IT TO JQUERY FUNCTIONS" -))

Changed April 10, 2009 11:30PM UTC by dmethvin comment:3

resolution: → fixed
status: newclosed

I updated the docs to make it clearer.