Opened 9 years ago

Closed 4 years ago

#11100 closed defect (fixed)

dojo.hash breaks when there's a base tag

Reported by: Rob Retchless Owned by: bill
Priority: high Milestone: 1.11
Component: General Version: 1.5.0b2
Keywords: Cc: websmith@…
Blocked By: Blocking:

Description

If there's a <base> tag on the page that points at a different server or path, calling dojo.hash("someHash") adds the hash to the value in the base tag and updates the URL, causing a page transition. Dojo.hash should fully qualify on set.

Attachments (3)

basehref_ff.html (692 bytes) - added by Marcel Lucas 9 years ago.
a sample page which shows the issue in Firefox (any other browser should react as expected)
hash.js.patch (308 bytes) - added by Marcel Lucas 9 years ago.
patchfile with the one affected line
hash.js.11100.patch (622 bytes) - added by Adam Peller 8 years ago.
patch from retchless (IBM, CCLA)

Download all attachments as: .zip

Change History (19)

comment:1 Changed 9 years ago by James Burke

Milestone: tbd1.5

retchless, I marked this for 1.5, but if you do not think you will have a patch ready by then, just give a holler.

comment:2 Changed 9 years ago by Adam Peller

Owner: changed from anonymous to Rob Retchless

comment:3 Changed 9 years ago by Rob Retchless

This is a trickier issue than expected, so let's defer to 1.6.

comment:4 Changed 9 years ago by dante

Milestone: 1.51.6

comment:5 Changed 9 years ago by bill

Milestone: 1.6future

(sadly) punting seemingly abandoned ticket and meta tickets to future

Changed 9 years ago by Marcel Lucas

Attachment: basehref_ff.html added

a sample page which shows the issue in Firefox (any other browser should react as expected)

Changed 9 years ago by Marcel Lucas

Attachment: hash.js.patch added

patchfile with the one affected line

comment:6 Changed 9 years ago by Marcel Lucas

This bug seems to only occur in Firefox (3.x). As stated above the the hash gets added to the value of <base href="..."> instead of being applied to the current location.href.

Means: Having a page on yourdomain.com with a base tag set to google.com using dojo.hash('someHash') will result in a redirect to google.com#someHash instead of yourdomain.com#someHash.

This is because doojo.hash utilizes location.href to apply the hash. Better use location.hash to accomplish this task.

ff_basehref.html is a sample page which shows the issue in Firefox (any other browser should react as expected) hash.js.patch is patchfile with the one affected line.

NOTE: _replace() has to be fixed as well because location.replace("#"+hash); would also redirect to the value given in base href.

comment:7 Changed 9 years ago by xMartin

The problem occurs also in WebKit? and FireFox? 4 but not in any IE incl. version 9 nor in Opera.

Anyway, the fix seems to be working for all.

comment:8 Changed 9 years ago by Rob Retchless

The patch looks good. My only concern is potential changes in encoding behaviour. I went with location.href because it had the most aligned encode/decode behaviour for getting and setting (IIRC, one of the browsers messed with spaces when using location.hash). If the test suite runs correctly with this patch, then we're good.

comment:9 Changed 8 years ago by xMartin

Any chance to get this out soon? Maybe even 1.7?

comment:10 Changed 8 years ago by Adam Peller

Milestone: future1.7.1

comment:11 Changed 8 years ago by Rob Retchless

Tested the patch above, and we're good to go for the non replace case (there are no encoding differences for the setting case, only the getting case).

I'm working on an updated patch for the replace case. The key is to read location.href first, and to call location.replace with the fully qualified URL. Firefox only applies the base tag when setting location.href, not when getting it.

Changed 8 years ago by Adam Peller

Attachment: hash.js.11100.patch added

patch from retchless (IBM, CCLA)

comment:12 Changed 8 years ago by Kenneth G. Franqueiro

Milestone: 1.7.11.8

Bumping to 1.8; can backport if there is a solid argument.

comment:13 Changed 8 years ago by Adam Peller

Tested in Chrome and the test fails. First button does not change the page nor the hash, second button changes the hash and browses to the page referenced by base

comment:14 Changed 7 years ago by Colin Snover

Milestone: 1.82.0

1.8 has been tagged; moving all outstanding tickets to next major release milestone.

comment:15 Changed 4 years ago by bill

Milestone: 2.01.11
Owner: changed from Rob Retchless to bill
Status: newassigned

comment:16 Changed 4 years ago by bill

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.