[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: Patch: allow KURL to parse #someReference?aQuery fault-tolerant
From: Tobias Anton <anton () stud ! fbi ! fh-darmstadt ! de>
Date: 2001-07-28 11:29:59
[Download RAW message or body]
Hi!
Here's a patch that allows kurl to parse urls with reversed order of query
and reference - forbidden according to the rfc, but there are sites out there
using it this way. consistent to Mozilla's behaviour, and, i think, IE would
tolerate it, too.
in combination with the second patch, this fixes konq's failure in the
mozilla-testsuite:
http://mozilla.org/quality/browser/standards/javascript/tcmatrix/are001.html
Cheers,
Tobias
["kurl.patch" (text/x-diff)]
? kurl.patch
Index: kurl.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kurl.cpp,v
retrieving revision 1.168
diff -u -r1.168 kurl.cpp
--- kurl.cpp 2001/07/19 07:42:41 1.168
+++ kurl.cpp 2001/07/28 08:56:53
@@ -521,6 +521,9 @@
QChar* orig = buf;
memcpy( buf, _url.unicode(), len * sizeof( QChar ) );
+ QChar delim;
+ QString tmp;
+
uint pos = 0;
// Node 1: Accept alpha or slash
@@ -554,7 +557,7 @@
{
m_strProtocol = QString( orig, pos ).lower();
pos++;
- goto Node11;
+ goto Node9;
}
else
goto NodeErr;
@@ -687,36 +690,39 @@
goto NodeOk;
start = pos++;
- // Node 9: Accept any character and # or terminate
- Node9:
- while( buf[pos] != '#' && pos < len ) pos++;
- if ( pos == len )
- {
- QString tmp( buf + start, len - start );
- setEncodedPathAndQuery( tmp, encoding_hint );
- // setEncodedPathAndQuery( QString( buf + start, pos - start ) );
+ Node9: // parse path until query or reference reached
+
+ while( buf[pos] != '#' && buf[pos]!='?' && pos < len ) pos++;
+
+ tmp = QString( buf + start, pos - start );
+ setEncodedPathAndQuery( tmp, encoding_hint );
+
+ if ( pos >= len-1 )
goto NodeOk;
- }
- else if ( buf[pos] != '#' )
- goto NodeErr;
- setEncodedPathAndQuery( QString( buf + start, pos - start ), encoding_hint );
- pos++;
- // Node 10: Accept all the rest
- m_strRef_encoded = QString( buf + pos, len - pos );
- goto NodeOk;
+ start = pos + 1;
- // Node 11 We need at least one character
- Node11:
- start = pos;
- if ( pos++ == len )
- goto NodeOk; // Wrong, but since a fix was applied up top it is a non-issue here!!!!
- // Just for the record an opaque URL such as "mailto:" is always required
- // to have at least one more character other than a '/' following the colon.
- // Node 12: Accept the res
- setEncodedPathAndQuery( QString( buf + start, len - start ), encoding_hint );
- goto NodeOk;
+ Node10: // parse query or reference depending on what comes first
+ delim = (buf[pos++]=='#'?'?':'#');
+
+ while(buf[pos]!=delim && pos < len) pos++;
+ if (pos == len)
+ goto NodeOk;
+
+ tmp = QString(buf + start, pos - start);
+ if (delim=='#')
+ m_strQuery_encoded = tmp;
+ else
+ m_strRef_encoded = tmp;
+
+ Node11: // feed the rest into the remaining variable
+ tmp = QString( buf + pos + 1, len - pos - 1);
+ if (delim == '#')
+ m_strRef_encoded = tmp;
+ else
+ m_strQuery_encoded = tmp;
+
NodeOk:
delete []orig;
m_bIsMalformed = false; // Valid URL
@@ -985,6 +991,17 @@
return tmp;
}
+void KURL::setEncodedPath( const QString& _txt, int encoding_hint )
+{
+ m_strPath_encoded = _txt;
+
+ bool keepEncoded;
+ m_strPath = decode( m_strPath_encoded, &keepEncoded, encoding_hint );
+ if (!keepEncoded)
+ m_strPath_encoded = QString::null;
+}
+
+
void KURL::setEncodedPathAndQuery( const QString& _txt, int encoding_hint )
{
int pos = _txt.find( '?' );
Index: kurl.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kurl.h,v
retrieving revision 1.76
diff -u -r1.76 kurl.h
--- kurl.h 2001/07/19 07:42:41 1.76
+++ kurl.h 2001/07/28 08:56:54
@@ -229,6 +229,8 @@
*/
void setEncodedPathAndQuery( const QString& _txt, int encoding_hint = 0 );
+ void setEncodedPath(const QString& _txt, int encoding_hint = 0 );
+
/**
* @return The concatenation if the encoded path , '?' and the encoded query.
*
["kjs_html.diff" (text/x-diff)]
Index: ecma/kjs_html.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.104
diff -u -r1.104 kjs_html.cpp
--- ecma/kjs_html.cpp 2001/07/18 10:37:57 1.104
+++ ecma/kjs_html.cpp 2001/07/28 09:06:03
@@ -45,7 +45,9 @@
#include <xml/dom_docimpl.h>
#include <xml/dom2_eventsimpl.h>
#include <khtmlview.h>
+#include <xml/dom_stringimpl.h>
+
#include <kjs/operations.h>
#include "kjs_dom.h"
#include "kjs_html.h"
@@ -305,6 +307,7 @@
if (p == "disabled") return Boolean(link.disabled());
else if (p == "charset") return getString(link.charset());
else if (p == "href") return getString(link.href());
+ else if (p == "hash") return getString('#'+KURL(link.href().string()).ref());
else if (p == "hreflang") return getString(link.hreflang());
else if (p == "media") return getString(link.media());
else if (p == "rel") return getString(link.rel());
@@ -621,6 +624,7 @@
else if (p == "coords") return getString(anchor.coords());
else if (p == "href") return getString(anchor.href());
else if (p == "hreflang") return getString(anchor.hreflang());
+ else if (p == "hash") return getString('#'+KURL(anchor.href().string()).ref());
else if (p == "name") return getString(anchor.name());
else if (p == "rel") return getString(anchor.rel());
else if (p == "rev") return getString(anchor.rev());
@@ -709,6 +713,7 @@
else if (p == "alt") return getString(area.alt());
else if (p == "coords") return getString(area.coords());
else if (p == "href") return getString(area.href());
+ else if (p == "hash") return getString('#'+KURL(area.href().string()).ref());
else if (p == "noHref") return Boolean(area.noHref());
else if (p == "shape") return getString(area.shape());
else if (p == "tabIndex") return Number(area.tabIndex());
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic