~ubuntu-branches/ubuntu/lucid/webkit/lucid-updates

« back to all changes in this revision

Viewing changes to WebCore/platform/KURL.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2010-02-04 19:30:57 UTC
  • mfrom: (1.2.8 upstream) (4.3.9 sid)
  • Revision ID: james.westby@ubuntu.com-20100204193057-d3018lm1fipb0703
* New upstream release
* debian/copyright:
- Updated with changes since 1.1.19.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "CString.h"
33
33
#include "StringHash.h"
34
34
#include "TextEncoding.h"
 
35
#include <wtf/HashMap.h>
35
36
#include <wtf/StdLibExtras.h>
36
37
 
37
38
#if USE(ICU_UNICODE)
38
39
#include <unicode/uidna.h>
39
40
#elif USE(QT4_UNICODE)
40
41
#include <QUrl>
 
42
#elif USE(GLIB_UNICODE)
 
43
#include <glib.h>
 
44
#include <wtf/gtk/GOwnPtr.h>
41
45
#endif
42
46
 
43
47
#include <stdio.h>
214
218
static int copyPathRemovingDots(char* dst, const char* src, int srcStart, int srcEnd);
215
219
static void encodeRelativeString(const String& rel, const TextEncoding&, CharBuffer& ouput);
216
220
static String substituteBackslashes(const String&);
 
221
static bool isValidProtocol(const String&);
217
222
 
218
223
static inline bool isSchemeFirstChar(char c) { return characterClassTable[static_cast<unsigned char>(c)] & SchemeFirstChar; }
219
224
static inline bool isSchemeFirstChar(UChar c) { return c <= 0xff && (characterClassTable[c] & SchemeFirstChar); }
659
664
    return decodeURLEscapeSequences(m_string.substring(m_portEnd, m_pathEnd - m_portEnd)); 
660
665
}
661
666
 
662
 
void KURL::setProtocol(const String& s)
 
667
bool KURL::setProtocol(const String& s)
663
668
{
664
 
    // FIXME: Non-ASCII characters must be encoded and escaped to match parse() expectations,
665
 
    // and to avoid changing more than just the protocol.
 
669
    // Firefox and IE remove everything after the first ':'.
 
670
    int separatorPosition = s.find(':');
 
671
    String newProtocol = s.substring(0, separatorPosition);
 
672
 
 
673
    if (!isValidProtocol(newProtocol))
 
674
        return false;
666
675
 
667
676
    if (!m_isValid) {
668
 
        parse(s + ":" + m_string);
669
 
        return;
 
677
        parse(newProtocol + ":" + m_string);
 
678
        return true;
670
679
    }
671
680
 
672
 
    parse(s + m_string.substring(m_schemeEnd));
 
681
    parse(newProtocol + m_string.substring(m_schemeEnd));
 
682
    return true;
673
683
}
674
684
 
675
685
void KURL::setHost(const String& s)
1404
1414
#elif USE(QT4_UNICODE)
1405
1415
    QByteArray result = QUrl::toAce(String(str, strLen));
1406
1416
    buffer.append(result.constData(), result.length());
 
1417
#elif USE(GLIB_UNICODE)
 
1418
    GOwnPtr<gchar> utf8Hostname;
 
1419
    GOwnPtr<GError> utf8Err;
 
1420
    utf8Hostname.set(g_utf16_to_utf8(str, strLen, 0, 0, &utf8Err.outPtr()));
 
1421
    if (utf8Err)
 
1422
        return;
 
1423
 
 
1424
    GOwnPtr<gchar> encodedHostname;
 
1425
    encodedHostname.set(g_hostname_to_ascii(utf8Hostname.get()));
 
1426
    if (!encodedHostname) 
 
1427
        return;
 
1428
 
 
1429
    buffer.append(encodedHostname.get(), strlen(encodedHostname.get()));
1407
1430
#endif
1408
1431
}
1409
1432
 
1630
1653
 
1631
1654
bool isValidProtocol(const String& protocol)
1632
1655
{
 
1656
    // RFC3986: ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
 
1657
    if (protocol.isEmpty())
 
1658
        return false;
1633
1659
    if (!isSchemeFirstChar(protocol[0]))
1634
1660
        return false;
1635
1661
    unsigned protocolLength = protocol.length();
1726
1752
        3659, // apple-sasl / PasswordServer [Apple addition]
1727
1753
        4045, // lockd
1728
1754
        6000, // X11
 
1755
        6665, // Alternate IRC [Apple addition]
 
1756
        6666, // Alternate IRC [Apple addition]
 
1757
        6667, // Standard IRC [Apple addition]
 
1758
        6668, // Alternate IRC [Apple addition]
 
1759
        6669, // Alternate IRC [Apple addition]
 
1760
 
1729
1761
    };
1730
1762
    const unsigned short* const blockedPortListEnd = blockedPortList + sizeof(blockedPortList) / sizeof(blockedPortList[0]);
1731
1763