Bug 159192 - window.location.hash's '#' get doubled
Summary: window.location.hash's '#' get doubled
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml (show other bugs)
Version: unspecified
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-12 16:54 UTC by Tim Landscheidt
Modified: 2008-06-29 00:09 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Landscheidt 2008-03-12 16:54:32 UTC
Version:            (using KDE 3.5.9)
Installed from:    Fedora RPMs
OS:                Linux

Stumbled upon on the German Wikipedia, where redirects to fragments are implemented (cf. <URI:http://de.wikipedia.org/wiki/Habemus_papam>) in this way:

--- cut here ---
<HTML>
  <HEAD>
    <TITLE>Test</TITLE>
    <SCRIPT>
      if (window.location.hash == "")
        window.location.hash = "#P1";
    </SCRIPT>
  </HEAD>

  <BODY>
    <P ID="p1">Test 1</P>
    <P ID="p2">Test 2</P>
    <P ID="p3">Test 3</P>
  </BODY>
</HTML>
--- cut here ---

The location bar then reads "[...]/test.html##p1" (note the double hashes), and subsequent reads of window.location.hash show the value "##p1".

  In the "Habemus papam" case, this (?) stops Konqueror from continuing to load the page (K wheel is immobile while the status line reads "9 Bilder von 12 geladen." ("9 images out of 12 loaded.")
Comment 1 Maksim Orlovich 2008-03-12 17:34:57 UTC
Thanks for the testcase.. Weird that is affects rendering...
Comment 2 Maksim Orlovich 2008-03-12 17:40:16 UTC
Yikes. The not showing bug is actually different --- it somehow stops parsing. 
Presumably one can avoid that by having hash-setting do gotoAnchor immediately, but it needs debugging..
Comment 3 Maksim Orlovich 2008-03-12 17:50:03 UTC
OK, the sequence is this:
1) .href is set, Location::put calls goURL, with a full URL
2) goURL sees a full URL, not just #foo, and requests an immediate redirection
from the part
3) KHTMLPart::executeScript notices the immediate redirection. It aborts the tokenizer, and starts a timeout-0 redirectionTimer
4) That calls urlSelected, which notices we're just going to the same page, 
and jumps to an anchor...

My initial tendency would be to make goURL's fragment test smarter, making it sync'd with the one in KHTMLPart::urlSelected, but that seems suboptimal. 
I guess the tokenizer kill is needed to make sure no further scripts run, though.


Comment 4 Maksim Orlovich 2008-03-12 17:54:02 UTC
Related testcase:
<HTML>
   <HEAD>
     <TITLE>Test</TITLE>
     <SCRIPT>
         window.location = "javascript:alert('hi')";
     </SCRIPT>
   </HEAD>

   <BODY>
     <P ID="p1">Test 1</P>
     <P ID="p2">Test 2</P>
     <P ID="p3">Test 3</P>
   </BODY>
 </HTML>
 
Comment 5 Maksim Orlovich 2008-03-12 17:58:57 UTC
More fun:
 <SCRIPT>
    window.location = "javascript:alert('hi')";
    window.location = "javascript:alert('cruel world')";
    alert(window.location);
 </SCRIPT>
Comment 6 S. Bryant 2008-06-19 11:58:53 UTC
I'm having problems with this bug under OpenSUSE 10.3, KDE 3.5.7.  Here's a workaround hack for JavaScript:

window.location.hash = hash;
if ( window.location.hash != hash )
{
  window.location.assign(
    window.location.toString().replace( /#.*/, "" ) + hash );
}

-- Steve
-- Steve
Comment 7 Maksim Orlovich 2008-06-29 00:09:17 UTC
SVN commit 825638 by orlovich:

Fix a number of issues related to redirections:
- Strip leading # if given to location.hash, as other browsers do (part of #159192); avoids
doubling it with various history frameworks, and stops confusing facebook's
photo view (#165221)
- Properly handle in-place redirects such as anchor jumps completely synchronously (part of #159192)
- More importantly, don't handle in-place redirects as changing pages, which aborts parsing.
Fixes some Wikipedia pages showing up blank.
- Properly update history on anchor jumps, including honoring locking (#159279, #137176)

Also, cleanup some of the handling of JavaScript URLs --- use the helpers I needed for above and not 10
different copies of string munging.

BUG:165221
BUG:159192
BUG:159279
BUG:137176


 M  +14 -15    ecma/kjs_window.cpp  
 M  +72 -38    khtml_part.cpp  
 M  +23 -1     khtmlpart_p.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=825638