OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 break; | 66 break; |
67 case '"': | 67 case '"': |
68 append(buffer, "%22"); | 68 append(buffer, "%22"); |
69 break; | 69 break; |
70 default: | 70 default: |
71 append(buffer, c); | 71 append(buffer, c); |
72 } | 72 } |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 WTF::TextEncoding FormDataEncoder::encodingFromAcceptCharset(const String& accep
tCharset, const String& charset, const String& defaultCharset) | 76 WTF::TextEncoding FormDataEncoder::encodingFromAcceptCharset(const String& accep
tCharset, const WTF::TextEncoding& fallbackEncoding) |
77 { | 77 { |
| 78 ASSERT(fallbackEncoding.isValid()); |
| 79 |
78 String normalizedAcceptCharset = acceptCharset; | 80 String normalizedAcceptCharset = acceptCharset; |
79 normalizedAcceptCharset.replace(',', ' '); | 81 normalizedAcceptCharset.replace(',', ' '); |
80 | 82 |
81 Vector<String> charsets; | 83 Vector<String> charsets; |
82 normalizedAcceptCharset.split(' ', charsets); | 84 normalizedAcceptCharset.split(' ', charsets); |
83 | 85 |
84 WTF::TextEncoding encoding; | 86 for (const String& name : charsets) { |
85 | 87 WTF::TextEncoding encoding(name); |
86 Vector<String>::const_iterator end = charsets.end(); | 88 if (encoding.isValid()) |
87 for (Vector<String>::const_iterator it = charsets.begin(); it != end; ++it)
{ | |
88 if ((encoding = WTF::TextEncoding(*it)).isValid()) | |
89 return encoding; | 89 return encoding; |
90 } | 90 } |
91 | 91 |
92 if (charset.isEmpty()) { | 92 return fallbackEncoding; |
93 if (defaultCharset.isEmpty()) | |
94 return WTF::UTF8Encoding(); | |
95 | |
96 return defaultCharset; | |
97 } | |
98 | |
99 return charset; | |
100 } | 93 } |
101 | 94 |
102 Vector<char> FormDataEncoder::generateUniqueBoundaryString() | 95 Vector<char> FormDataEncoder::generateUniqueBoundaryString() |
103 { | 96 { |
104 Vector<char> boundary; | 97 Vector<char> boundary; |
105 | 98 |
106 // TODO(rsleevi): crbug.com/575779: Follow the spec or fix the spec. | 99 // TODO(rsleevi): crbug.com/575779: Follow the spec or fix the spec. |
107 // The RFC 2046 spec says the alphanumeric characters plus the | 100 // The RFC 2046 spec says the alphanumeric characters plus the |
108 // following characters are legal for boundaries: '()+_,-./:=? | 101 // following characters are legal for boundaries: '()+_,-./:=? |
109 // However the following characters, though legal, cause some sites | 102 // However the following characters, though legal, cause some sites |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } else if (c == '\n' || (c == '\r' && (i + 1 >= length || string.data()[
i + 1] != '\n'))) { | 211 } else if (c == '\n' || (c == '\r' && (i + 1 >= length || string.data()[
i + 1] != '\n'))) { |
219 append(buffer, "%0D%0A"); | 212 append(buffer, "%0D%0A"); |
220 } else if (c != '\r') { | 213 } else if (c != '\r') { |
221 append(buffer, '%'); | 214 append(buffer, '%'); |
222 appendByteAsHex(c, buffer); | 215 appendByteAsHex(c, buffer); |
223 } | 216 } |
224 } | 217 } |
225 } | 218 } |
226 | 219 |
227 } // namespace blink | 220 } // namespace blink |
OLD | NEW |