Bug Tracker

Ticket #4498 (closed feature: fixed)

Opened 6 years ago

Last modified 6 years ago

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:
Blocking: Blocked by:

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)

Change History

comment:1 follow-up: ↓ 2 Changed 6 years ago by 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.

comment:2 in reply to: ↑ 1 Changed 6 years ago by oluckyman

Replying to 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" -))

comment:3 Changed 6 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed

I updated the docs to make it clearer.

Note: See TracTickets for help on using tickets.