| Index: Source/core/html/FormDataList.cpp
|
| diff --git a/Source/core/html/FormDataList.cpp b/Source/core/html/FormDataList.cpp
|
| index e4f62cfab4f24738d11e3f3a23bbed8cb6e067f3..9c33722b4a8bc395786a5b5087c7d756fbd9ee74 100644
|
| --- a/Source/core/html/FormDataList.cpp
|
| +++ b/Source/core/html/FormDataList.cpp
|
| @@ -33,49 +33,31 @@ FormDataList::FormDataList(const WTF::TextEncoding& c)
|
| {
|
| }
|
|
|
| -void FormDataList::appendString(const String& string)
|
| +void FormDataList::appendItem(const FormDataList::Item& item)
|
| {
|
| - m_items.append(encodeAndNormalize(string));
|
| -}
|
| -
|
| -void FormDataList::appendString(const CString& string)
|
| -{
|
| - m_items.append(string);
|
| -}
|
| -
|
| -void FormDataList::appendBlob(Blob* blob, const String& filename)
|
| -{
|
| - m_items.append(Item(blob, filename));
|
| + m_items.append(item);
|
| }
|
|
|
| void FormDataList::deleteEntry(const String& key)
|
| {
|
| const CString keyData = encodeAndNormalize(key);
|
| - ASSERT(!(m_items.size() % 2));
|
| size_t i = 0;
|
| while (i < m_items.size()) {
|
| - if (m_items[i].data() == keyData) {
|
| - m_items.remove(i, 2);
|
| + if (m_items[i].key() == keyData) {
|
| + m_items.remove(i);
|
| } else {
|
| - i += 2;
|
| + ++i;
|
| }
|
| }
|
| - ASSERT(!(m_items.size() % 2));
|
| return;
|
| }
|
|
|
| FormDataList::Entry FormDataList::getEntry(const String& key) const
|
| {
|
| const CString keyData = encodeAndNormalize(key);
|
| - const FormDataListItems& items = this->items();
|
| - size_t formDataListSize = items.size();
|
| - ASSERT(!(formDataListSize % 2));
|
| - for (size_t i = 0; i < formDataListSize; i += 2) {
|
| - const FormDataList::Item& key = items[i];
|
| - if (key.data() != keyData)
|
| - continue;
|
| - const FormDataList::Item& value = items[i + 1];
|
| - return itemsToEntry(key, value);
|
| + for (const Item& item : items()) {
|
| + if (item.key() == keyData)
|
| + return itemsToEntry(item);
|
| }
|
| return Entry();
|
| }
|
| @@ -83,13 +65,9 @@ FormDataList::Entry FormDataList::getEntry(const String& key) const
|
| FormDataList::Entry FormDataList::getEntry(size_t index) const
|
| {
|
| const FormDataListItems& items = this->items();
|
| - size_t formDataListSize = items.size();
|
| - ASSERT(!(formDataListSize % 2));
|
| - if (index >= formDataListSize / 2)
|
| + if (index >= items.size())
|
| return Entry();
|
| - const FormDataList::Item& key = items[index * 2];
|
| - const FormDataList::Item& value = items[index * 2 + 1];
|
| - return itemsToEntry(key, value);
|
| + return itemsToEntry(items[index]);
|
| }
|
|
|
| HeapVector<FormDataList::Entry> FormDataList::getAll(const String& key) const
|
| @@ -97,27 +75,21 @@ HeapVector<FormDataList::Entry> FormDataList::getAll(const String& key) const
|
| HeapVector<FormDataList::Entry> matches;
|
|
|
| const CString keyData = encodeAndNormalize(key);
|
| - const FormDataListItems& items = this->items();
|
| - size_t formDataListSize = items.size();
|
| - ASSERT(!(formDataListSize % 2));
|
| - for (size_t i = 0; i < formDataListSize; i += 2) {
|
| - const FormDataList::Item& key = items[i];
|
| - if (key.data() != keyData)
|
| - continue;
|
| - const FormDataList::Item& value = items[i + 1];
|
| - matches.append(itemsToEntry(key, value));
|
| + for (const Item& item : items()) {
|
| + if (item.key() == keyData)
|
| + matches.append(itemsToEntry(item));
|
| }
|
|
|
| return matches;
|
| }
|
|
|
| -FormDataList::Entry FormDataList::itemsToEntry(const FormDataList::Item& key, const FormDataList::Item& value) const
|
| +FormDataList::Entry FormDataList::itemsToEntry(const FormDataList::Item& item) const
|
| {
|
| - const CString nameData = key.data();
|
| + const CString nameData = item.key();
|
| const String name = m_encoding.decode(nameData.data(), nameData.length());
|
|
|
| - if (!value.blob()) {
|
| - const CString valueData = value.data();
|
| + if (!item.blob()) {
|
| + const CString valueData = item.data();
|
| return Entry(name, m_encoding.decode(valueData.data(), valueData.length()));
|
| }
|
|
|
| @@ -126,28 +98,24 @@ FormDataList::Entry FormDataList::itemsToEntry(const FormDataList::Item& key, co
|
| // items.
|
| // FIXME: Consider applying the name during insertion.
|
|
|
| - if (value.blob()->isFile()) {
|
| - File* file = toFile(value.blob());
|
| - if (value.filename().isNull())
|
| + if (item.blob()->isFile()) {
|
| + File* file = toFile(item.blob());
|
| + if (item.filename().isNull())
|
| return Entry(name, file);
|
| - return Entry(name, file->clone(value.filename()));
|
| + return Entry(name, file->clone(item.filename()));
|
| }
|
|
|
| - String filename = value.filename();
|
| + String filename = item.filename();
|
| if (filename.isNull())
|
| filename = "blob";
|
| - return Entry(name, File::create(filename, currentTimeMS(), value.blob()->blobDataHandle()));
|
| + return Entry(name, File::create(filename, currentTimeMS(), item.blob()->blobDataHandle()));
|
| }
|
|
|
| bool FormDataList::hasEntry(const String& key) const
|
| {
|
| const CString keyData = encodeAndNormalize(key);
|
| - const FormDataListItems& items = this->items();
|
| - size_t formDataListSize = items.size();
|
| - ASSERT(!(formDataListSize % 2));
|
| - for (size_t i = 0; i < formDataListSize; i += 2) {
|
| - const FormDataList::Item& key = items[i];
|
| - if (key.data() == keyData)
|
| + for (const Item& item : items()) {
|
| + if (item.key() == keyData)
|
| return true;
|
| }
|
| return false;
|
| @@ -155,36 +123,32 @@ bool FormDataList::hasEntry(const String& key) const
|
|
|
| void FormDataList::setBlob(const String& key, Blob* blob, const String& filename)
|
| {
|
| - setEntry(key, Item(blob, filename));
|
| + setEntry(Item(encodeAndNormalize(key), blob, filename));
|
| }
|
|
|
| void FormDataList::setData(const String& key, const String& value)
|
| {
|
| - setEntry(key, encodeAndNormalize(value));
|
| + setEntry(Item(encodeAndNormalize(key), encodeAndNormalize(value)));
|
| }
|
|
|
| -void FormDataList::setEntry(const String& key, const Item& item)
|
| +void FormDataList::setEntry(const Item& item)
|
| {
|
| - const CString keyData = encodeAndNormalize(key);
|
| - ASSERT(!(m_items.size() % 2));
|
| + const CString keyData = item.key();
|
| bool found = false;
|
| size_t i = 0;
|
| while (i < m_items.size()) {
|
| - if (m_items[i].data() != keyData) {
|
| - i += 2;
|
| + if (m_items[i].key() != keyData) {
|
| + ++i;
|
| } else if (found) {
|
| - m_items.remove(i, 2);
|
| + m_items.remove(i);
|
| } else {
|
| found = true;
|
| - m_items[i + 1] = item;
|
| - i += 2;
|
| + m_items[i] = item;
|
| + ++i;
|
| }
|
| }
|
| - if (!found) {
|
| - m_items.append(keyData);
|
| + if (!found)
|
| m_items.append(item);
|
| - }
|
| - ASSERT(!(m_items.size() % 2));
|
| return;
|
| }
|
|
|
| @@ -209,31 +173,26 @@ void FormDataList::appendKeyValuePairItemsTo(FormData* formData, const WTF::Text
|
|
|
| Vector<char> encodedData;
|
|
|
| - const FormDataListItems& items = this->items();
|
| - size_t formDataListSize = items.size();
|
| - ASSERT(!(formDataListSize % 2));
|
| - for (size_t i = 0; i < formDataListSize; i += 2) {
|
| - const FormDataList::Item& key = items[i];
|
| - const FormDataList::Item& value = items[i + 1];
|
| + for (const Item& item : items()) {
|
| if (isMultiPartForm) {
|
| Vector<char> header;
|
| - FormDataBuilder::beginMultiPartHeader(header, formData->boundary().data(), key.data());
|
| + FormDataBuilder::beginMultiPartHeader(header, formData->boundary().data(), item.key());
|
|
|
| // If the current type is blob, then we also need to include the filename
|
| - if (value.blob()) {
|
| + if (item.blob()) {
|
| String name;
|
| - if (value.blob()->isFile()) {
|
| - File* file = toFile(value.blob());
|
| + if (item.blob()->isFile()) {
|
| + File* file = toFile(item.blob());
|
| // For file blob, use the filename (or relative path if it is present) as the name.
|
| name = file->webkitRelativePath().isEmpty() ? file->name() : file->webkitRelativePath();
|
|
|
| // If a filename is passed in FormData.append(), use it instead of the file blob's name.
|
| - if (!value.filename().isNull())
|
| - name = value.filename();
|
| + if (!item.filename().isNull())
|
| + name = item.filename();
|
| } else {
|
| // For non-file blob, use the filename if it is passed in FormData.append().
|
| - if (!value.filename().isNull())
|
| - name = value.filename();
|
| + if (!item.filename().isNull())
|
| + name = item.filename();
|
| else
|
| name = "blob";
|
| }
|
| @@ -243,10 +202,10 @@ void FormDataList::appendKeyValuePairItemsTo(FormData* formData, const WTF::Text
|
|
|
| // Add the content type if available, or "application/octet-stream" otherwise (RFC 1867).
|
| String contentType;
|
| - if (value.blob()->type().isEmpty())
|
| + if (item.blob()->type().isEmpty())
|
| contentType = "application/octet-stream";
|
| else
|
| - contentType = value.blob()->type();
|
| + contentType = item.blob()->type();
|
| FormDataBuilder::addContentTypeToMultiPartHeader(header, contentType.latin1());
|
| }
|
|
|
| @@ -254,23 +213,23 @@ void FormDataList::appendKeyValuePairItemsTo(FormData* formData, const WTF::Text
|
|
|
| // Append body
|
| formData->appendData(header.data(), header.size());
|
| - if (value.blob()) {
|
| - if (value.blob()->hasBackingFile()) {
|
| - File* file = toFile(value.blob());
|
| + if (item.blob()) {
|
| + if (item.blob()->hasBackingFile()) {
|
| + File* file = toFile(item.blob());
|
| // Do not add the file if the path is empty.
|
| if (!file->path().isEmpty())
|
| formData->appendFile(file->path());
|
| if (!file->fileSystemURL().isEmpty())
|
| formData->appendFileSystemURL(file->fileSystemURL());
|
| } else {
|
| - formData->appendBlob(value.blob()->uuid(), value.blob()->blobDataHandle());
|
| + formData->appendBlob(item.blob()->uuid(), item.blob()->blobDataHandle());
|
| }
|
| } else {
|
| - formData->appendData(value.data().data(), value.data().length());
|
| + formData->appendData(item.data().data(), item.data().length());
|
| }
|
| formData->appendData("\r\n", 2);
|
| } else {
|
| - FormDataBuilder::addKeyValuePairAsFormData(encodedData, key.data(), value.data(), encodingType);
|
| + FormDataBuilder::addKeyValuePairAsFormData(encodedData, item.key(), item.data(), encodingType);
|
| }
|
| }
|
|
|
|
|