Exemple #1
0
DOMString ElementImpl::openTagStartToString(bool expandurls) const
{
    DOMString result = DOMString("<") + tagName();

    NamedAttrMapImpl *attrMap = attributes(true);

    if(attrMap)
    {
        unsigned long numAttrs = attrMap->length();
        for(unsigned long i = 0; i < numAttrs; i++)
        {
            result += " ";

            AttributeImpl *attribute = attrMap->attrAt(i);
            AttrImpl *attr = attribute->attr();

            if(attr)
            {
                result += attr->toString();
            }
            else
            {
                result += getDocument()->getName(NodeImpl::AttributeId, attribute->id());
                if(!attribute->value().isNull())
                {
                    result += "=\"";
                    // FIXME: substitute entities for any instances of " or '
                    // Expand out all urls, i.e. the src and href attributes
                    if(expandurls && (attribute->id() == ATTR_SRC || attribute->id() == ATTR_HREF))
                        if(getDocument())
                        {
                            // We need to sanitize the urls - strip out the passwords.
                            // FIXME:   are src=  and href=  the only places that might have a password and need to be sanitized?
                            KURL safeURL(getDocument()->completeURL(attribute->value().string()));
                            safeURL.setPass(QString::null);
                            result += safeURL.htmlURL();
                        }
                        else
                        {
                            kdWarning() << "getDocument() returned false";
                            result += attribute->value();
                        }
                    else
                        result += attribute->value();
                    result += "\"";
                }
            }
        }
    }

    return result;
}