patch: resolve DOM src and href attributes against base
Maciej Stachowiak
mjs at apple.com
Tue Oct 28 11:17:11 CET 2003
This matches what other browsers do and my reading of the spec.
-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/ChangeLog,v
retrieving revision 1.2134
diff -u -p -r1.2134 ChangeLog
--- ChangeLog 2003/10/28 16:46:23 1.2134
+++ ChangeLog 2003/10/28 18:51:27
@@ -1,3 +1,30 @@
+2003-10-28 Maciej Stachowiak <mjs at apple.com>
+
+ Reviewed by NOBODY (OOPS!).
+
+ - fixed 3427046 - href and src attributes don't always give resolved URL
+
+ It turns out that all href and src attributes should be resolved
+ against the base, except for frame elements.
+
+ * khtml/dom/html_base.cpp:
+ (HTMLIFrameElement::src): Resolve against base URL.
+ * khtml/dom/html_form.cpp:
+ (HTMLInputElement::src): Resolve URL even when empty. Remove
+ comment questioning resolution against base - it's definitely
+ right.
+ * khtml/dom/html_head.cpp:
+ (HTMLBaseElement::href): Resolve against base URL.
+ (HTMLLinkElement::href): Ditto.
+ (HTMLScriptElement::src): Ditto.
+ * khtml/dom/html_image.cpp:
+ (HTMLAreaElement::href): Ditto.
+ (HTMLImageElement::src): Resolve URL even when empty. Remove
+ comment questioning resolution against base - it's definitely
+ right.
+ * khtml/dom/html_inline.cpp:
+ (HTMLAnchorElement::href): Resolve against base URL.
+
2003-10-28 Darin Adler <darin at apple.com>
Reviewed by John.
Index: khtml/dom/html_base.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/dom/html_base.cpp,v
retrieving revision 1.4
diff -u -p -r1.4 khtml/dom/html_base.cpp
--- khtml/dom/html_base.cpp 2002/06/10 20:07:34 1.4
+++ khtml/dom/html_base.cpp 2003/10/28 18:51:27
@@ -370,7 +370,9 @@ void HTMLIFrameElement::setScrolling( co
DOMString HTMLIFrameElement::src() const
{
if(!impl) return DOMString();
- return ((ElementImpl *)impl)->getAttribute(ATTR_SRC);
+ DOMString s = ((ElementImpl *)impl)->getAttribute(ATTR_SRC);
+ s = ownerDocument().completeURL( s );
+ return s;
}
void HTMLIFrameElement::setSrc( const DOMString &value )
Index: khtml/dom/html_form.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/dom/html_form.cpp,v
retrieving revision 1.5
diff -u -p -r1.5 khtml/dom/html_form.cpp
--- khtml/dom/html_form.cpp 2003/01/02 23:22:00 1.5
+++ khtml/dom/html_form.cpp 2003/10/28 18:51:27
@@ -464,10 +464,7 @@ DOMString HTMLInputElement::src() const
{
if(!impl) return DOMString();
DOMString s = static_cast<ElementImpl*>(impl)->getAttribute(ATTR_SRC);
- // ### not sure if we're supposed to do the completion
- if ( !s.isEmpty() )
- s = ownerDocument().completeURL( s );
-
+ s = ownerDocument().completeURL( s );
return s;
}
Index: khtml/dom/html_head.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/dom/html_head.cpp,v
retrieving revision 1.6
diff -u -p -r1.6 khtml/dom/html_head.cpp
--- khtml/dom/html_head.cpp 2003/06/05 19:05:32 1.6
+++ khtml/dom/html_head.cpp 2003/10/28 18:51:27
@@ -22,6 +22,7 @@
// --------------------------------------------------------------------------
#include "dom/html_head.h"
+#include "dom/dom_doc.h"
#include "html/html_headimpl.h"
#include "misc/htmlhashes.h"
@@ -58,7 +59,9 @@ HTMLBaseElement::~HTMLBaseElement()
DOMString HTMLBaseElement::href() const
{
if(!impl) return DOMString();
- return ((ElementImpl *)impl)->getAttribute(ATTR_HREF);
+ DOMString s = ((ElementImpl *)impl)->getAttribute(ATTR_HREF);
+ s = ownerDocument().completeURL( s );
+ return s;
}
void HTMLBaseElement::setHref( const DOMString &value )
@@ -135,7 +138,9 @@ void HTMLLinkElement::setCharset( const
DOMString HTMLLinkElement::href() const
{
if(!impl) return DOMString();
- return ((ElementImpl *)impl)->getAttribute(ATTR_HREF);
+ DOMString s = ((ElementImpl *)impl)->getAttribute(ATTR_HREF);
+ s = ownerDocument().completeURL( s );
+ return s;
}
void HTMLLinkElement::setHref( const DOMString &value )
@@ -379,7 +384,9 @@ void HTMLScriptElement::setDefer( bool _
DOMString HTMLScriptElement::src() const
{
if(!impl) return DOMString();
- return ((ElementImpl *)impl)->getAttribute(ATTR_SRC);
+ DOMString s = ((ElementImpl *)impl)->getAttribute(ATTR_SRC);
+ s = ownerDocument().completeURL( s );
+ return s;
}
void HTMLScriptElement::setSrc( const DOMString &value )
Index: khtml/dom/html_image.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/dom/html_image.cpp,v
retrieving revision 1.7
diff -u -p -r1.7 khtml/dom/html_image.cpp
--- khtml/dom/html_image.cpp 2003/01/22 00:12:33 1.7
+++ khtml/dom/html_image.cpp 2003/10/28 18:51:27
@@ -96,7 +96,9 @@ void HTMLAreaElement::setCoords( const D
DOMString HTMLAreaElement::href() const
{
if(!impl) return DOMString();
- return ((ElementImpl *)impl)->getAttribute(ATTR_HREF);
+ DOMString s = ((ElementImpl *)impl)->getAttribute(ATTR_HREF);
+ s = ownerDocument().completeURL( s );
+ return s;
}
void HTMLAreaElement::setHref( const DOMString &value )
@@ -287,9 +289,7 @@ DOMString HTMLImageElement::src() const
{
if(!impl) return DOMString();
DOMString s = ((ElementImpl *)impl)->getAttribute(ATTR_SRC);
- // ### not sure if we're supposed to do the completion
- if ( !s.isEmpty() )
- s = ownerDocument().completeURL( s );
+ s = ownerDocument().completeURL( s );
return s;
}
Index: khtml/dom/html_inline.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/dom/html_inline.cpp,v
retrieving revision 1.4
diff -u -p -r1.4 khtml/dom/html_inline.cpp
--- khtml/dom/html_inline.cpp 2002/06/10 20:07:35 1.4
+++ khtml/dom/html_inline.cpp 2003/10/28 18:51:27
@@ -95,7 +95,9 @@ void HTMLAnchorElement::setCoords( const
DOMString HTMLAnchorElement::href() const
{
if(!impl) return DOMString();
- return ((ElementImpl *)impl)->getAttribute(ATTR_HREF);
+ DOMString s = ((ElementImpl *)impl)->getAttribute(ATTR_HREF);
+ s = ownerDocument().completeURL( s );
+ return s;
}
void HTMLAnchorElement::setHref( const DOMString &value )
More information about the Khtml-devel
mailing list