void MarkupFormatter::appendQuotedURLAttributeValue(StringBuilder& result, const Element& element, const Attribute& attribute)
{
    ASSERT(element.isURLAttribute(attribute));
    const String resolvedURLString = resolveURLIfNeeded(element, attribute.value());
    UChar quoteChar = '"';
    String strippedURLString = resolvedURLString.stripWhiteSpace();
    if (protocolIsJavaScript(strippedURLString)) {
        // minimal escaping for javascript urls
        if (strippedURLString.contains('&'))
            strippedURLString.replaceWithLiteral('&', "&");

        if (strippedURLString.contains('"')) {
            if (strippedURLString.contains('\''))
                strippedURLString.replaceWithLiteral('"', """);
            else
                quoteChar = '\'';
        }
        result.append(quoteChar);
        result.append(strippedURLString);
        result.append(quoteChar);
        return;
    }

    // FIXME: This does not fully match other browsers. Firefox percent-escapes non-ASCII characters for innerHTML.
    result.append(quoteChar);
    appendAttributeValue(result, resolvedURLString, false);
    result.append(quoteChar);
}
Пример #2
0
static inline void transformTextStringToXHTMLDocumentString(String& text)
{
    // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing the text.
    text.replaceWithLiteral('&', "&amp;");
    text.replaceWithLiteral('<', "&lt;");
    text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
           "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
           "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
           "<head><title/></head>\n"
           "<body>\n"
           "<pre>" + text + "</pre>\n"
           "</body>\n"
           "</html>\n";
}
void InlineTextBox::showBox(int printedCharacters) const
{
    String value = text();
    value.replaceWithLiteral('\\', "\\\\");
    value.replaceWithLiteral('\n', "\\n");
    printedCharacters += fprintf(stderr, "%s %p", boxName(), this);
    for (; printedCharacters < showTreeCharacterOffset; printedCharacters++)
        fputc(' ', stderr);
    const LineLayoutText obj = lineLayoutItem();
    printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), obj.debugPointer());
    const int layoutObjectCharacterOffset = 75;
    for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++)
        fputc(' ', stderr);
    fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().data());
}
Пример #4
0
void HTMLAnchorElement::setSearch(const String& value)
{
    URL url = href();
    String newSearch = (value[0] == '?') ? value.substring(1) : value;
    // Make sure that '#' in the query does not leak to the hash.
    url.setQuery(newSearch.replaceWithLiteral('#', "%23"));

    setHref(url.string());
}
Пример #5
0
static void appendMailtoPostFormDataToURL(KURL& url, const FormData& data, const String& encodingType)
{
    String body = data.flattenToString();

    if (equalIgnoringCase(encodingType, "text/plain")) {
        // Convention seems to be to decode, and s/&/\r\n/. Also, spaces are encoded as %20.
        body = decodeURLEscapeSequences(body.replaceWithLiteral('&', "\r\n").replace('+', ' ') + "\r\n");
    }

    Vector<char> bodyData;
    bodyData.append("body=", 5);
    FormDataBuilder::encodeStringAsFormData(bodyData, body.utf8());
    body = String(bodyData.data(), bodyData.size()).replaceWithLiteral('+', "%20");

    String query = url.query();
    if (!query.isEmpty())
        query.append('&');
    query.append(body);
    url.setQuery(query);
}
Пример #6
0
TEST(StringTest, ReplaceWithLiteral)
{
    // Cases for 8Bit source.
    String testString = "1224";
    EXPECT_TRUE(testString.is8Bit());
    testString.replaceWithLiteral('2', "");
    EXPECT_STREQ("14", testString.utf8().data());

    testString = "1224";
    EXPECT_TRUE(testString.is8Bit());
    testString.replaceWithLiteral('2', "3");
    EXPECT_STREQ("1334", testString.utf8().data());

    testString = "1224";
    EXPECT_TRUE(testString.is8Bit());
    testString.replaceWithLiteral('2', "555");
    EXPECT_STREQ("15555554", testString.utf8().data());

    testString = "1224";
    EXPECT_TRUE(testString.is8Bit());
    testString.replaceWithLiteral('3', "NotFound");
    EXPECT_STREQ("1224", testString.utf8().data());

    // Cases for 16Bit source.
    // U+00E9 (=0xC3 0xA9 in UTF-8) is e with accent.
    testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
    EXPECT_FALSE(testString.is8Bit());
    testString.replaceWithLiteral(UChar(0x00E9), "e");
    EXPECT_STREQ("resume", testString.utf8().data());

    testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
    EXPECT_FALSE(testString.is8Bit());
    testString.replaceWithLiteral(UChar(0x00E9), "");
    EXPECT_STREQ("rsum", testString.utf8().data());

    testString = String::fromUTF8("r\xC3\xA9sum\xC3\xA9");
    EXPECT_FALSE(testString.is8Bit());
    testString.replaceWithLiteral('3', "NotFound");
    EXPECT_STREQ("r\xC3\xA9sum\xC3\xA9", testString.utf8().data());
}
Пример #7
0
TEST(WTF, StringReplaceWithLiteral)
{
    // Cases for 8Bit source.
    String testString = "1224";
    ASSERT_TRUE(testString.is8Bit());
    testString.replaceWithLiteral('2', "");
    ASSERT_STREQ("14", testString.utf8().data());

    testString = "1224";
    ASSERT_TRUE(testString.is8Bit());
    testString.replaceWithLiteral('2', "3");
    ASSERT_STREQ("1334", testString.utf8().data());

    testString = "1224";
    ASSERT_TRUE(testString.is8Bit());
    testString.replaceWithLiteral('2', "555");
    ASSERT_STREQ("15555554", testString.utf8().data());

    testString = "1224";
    ASSERT_TRUE(testString.is8Bit());
    testString.replaceWithLiteral('3', "NotFound");
    ASSERT_STREQ("1224", testString.utf8().data());

    // Cases for 16Bit source.
    testString = String::fromUTF8("résumé");
    ASSERT_FALSE(testString.is8Bit());
    testString.replaceWithLiteral(UChar(0x00E9 /*U+00E9 is 'é'*/), "e");
    ASSERT_STREQ("resume", testString.utf8().data());

    testString = String::fromUTF8("résumé");
    ASSERT_FALSE(testString.is8Bit());
    testString.replaceWithLiteral(UChar(0x00E9 /*U+00E9 is 'é'*/), "");
    ASSERT_STREQ("rsum", testString.utf8().data());

    testString = String::fromUTF8("résumé");
    ASSERT_FALSE(testString.is8Bit());
    testString.replaceWithLiteral('3', "NotFound");
    ASSERT_STREQ("résumé", testString.utf8().data());
}