Source/JavaScriptCore/ChangeLog

 12011-05-05 Jay Civelli <jcivelli@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Added convenience methods to convert from a byte to hex ASCII digit
 6 characters and vice-versa.
 7 https://bugs.webkit.org/show_bug.cgi?id=59834
 8
 9 * wtf/ASCIICType.h:
 10 (WTF::toASCIIHexValue):
 11 (WTF::lowerNibbleToASCIIHexDigit):
 12 (WTF::upperNibbleToASCIIHexDigit):
 13
1142011-05-05 Alexis Menard <alexis.menard@openbossa.org>
215
316 Reviewed by Benjamin Poulain.

Source/JavaScriptCore/wtf/ASCIICType.h

@@namespace WTF {
146146 inline unsigned toASCIIUpper(unsigned c) { return static_cast<unsigned>(c & ~((c >= 'a' && c <= 'z') << 5)); }
147147
148148 inline int toASCIIHexValue(char c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
 149 inline int toASCIIHexValue(char upperValue, char lowerValue) { ASSERT(isASCIIHexDigit(upperValue) && isASCIIHexDigit(lowerValue)); return ((toASCIIHexValue(upperValue) << 4) & 0xF0) | toASCIIHexValue(lowerValue); }
149150 inline int toASCIIHexValue(unsigned short c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
150151#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
151152 inline int toASCIIHexValue(wchar_t c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }

@@namespace WTF {
153154 inline int toASCIIHexValue(int c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
154155 inline int toASCIIHexValue(unsigned c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
155156
 157 inline char lowerNibbleToASCIIHexDigit(char c) { char nibble = c & 0xF; return nibble < 10 ? '0' + nibble : 'A' + nibble - 10; }
 158 inline char upperNibbleToASCIIHexDigit(char c) { char nibble = (c >> 4) & 0xF; return nibble < 10 ? '0' + nibble : 'A' + nibble - 10; }
 159
156160 inline bool isASCIIPrintable(char c) { return c >= ' ' && c <= '~'; }
157161 inline bool isASCIIPrintable(unsigned short c) { return c >= ' ' && c <= '~'; }
158162#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)

@@using WTF::isASCIIUpper;
175179using WTF::toASCIIHexValue;
176180using WTF::toASCIILower;
177181using WTF::toASCIIUpper;
 182using WTF::lowerNibbleToASCIIHexDigit;
 183using WTF::upperNibbleToASCIIHexDigit;
178184
179185#endif

Source/WebCore/CMakeLists.txt

@@SET(WebCore_SOURCES
11691169
11701170 platform/text/Base64.cpp
11711171 platform/text/BidiContext.cpp
 1172 platform/text/Hyphenation.cpp
11721173 platform/text/LineEnding.cpp
11731174 platform/text/LocalizedDateNone.cpp
11741175 platform/text/LocalizedNumberNone.cpp
1175  platform/text/Hyphenation.cpp
 1176 platform/text/QuotedPrintable.cpp
11761177 platform/text/RegularExpression.cpp
11771178 platform/text/SegmentedString.cpp
11781179 platform/text/String.cpp

Source/WebCore/ChangeLog

 12011-05-02 Jay Civelli <jcivelli@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Adding quoted-printable encoding/decoding capabilities.
 6 This is needed for MHTML support.
 7 https://bugs.webkit.org/show_bug.cgi?id=59834
 8
 9 * CMakeLists.txt:
 10 * GNUmakefile.list.am:
 11 * WebCore.gypi:
 12 * WebCore.pro:
 13 * WebCore.vcproj/WebCore.vcproj:
 14 * WebCore.xcodeproj/project.pbxproj:
 15 * platform/text/QuotedPrintable.cpp: Added.
 16 * platform/text/QuotedPrintable.h: Added.
 17
1182011-05-05 Justin Novosad <junov@chromium.org>
219
320 Reviewed by Kenneth Russell.

Source/WebCore/GNUmakefile.list.am

@@webcore_sources += \
26372637 Source/WebCore/platform/text/LocalizedNumberNone.cpp \
26382638 Source/WebCore/platform/text/ParserUtilities.h \
26392639 Source/WebCore/platform/text/PlatformString.h \
 2640 Source/WebCore/platform/text/QuotedPrintable.cpp \
 2641 Source/WebCore/platform/text/QuotedPrintable.h \
26402642 Source/WebCore/platform/text/RegularExpression.cpp \
26412643 Source/WebCore/platform/text/RegularExpression.h \
26422644 Source/WebCore/platform/text/SegmentedString.cpp \

Source/WebCore/WebCore.gypi

49074907 'platform/text/LocalizedNumberICU.cpp',
49084908 'platform/text/LocalizedNumberNone.cpp',
49094909 'platform/text/ParserUtilities.h',
 4910 'platform/text/QuotedPrintable.h',
 4911 'platform/text/QuotedPrintable.cpp',
49104912 'platform/text/RegularExpression.cpp',
49114913 'platform/text/SegmentedString.cpp',
49124914 'platform/text/String.cpp',

Source/WebCore/WebCore.pro

@@SOURCES += \
947947 platform/text/Hyphenation.cpp \
948948 platform/text/LocalizedDateNone.cpp \
949949 platform/text/LocalizedNumberNone.cpp \
 950 platform/text/QuotedPrintable.cpp \
950951 platform/ContentType.cpp \
951952 platform/CrossThreadCopier.cpp \
952953 platform/DateComponents.cpp \

@@HEADERS += \
20382039 platform/text/Base64.h \
20392040 platform/text/BidiContext.h \
20402041 platform/text/Hyphenation.h \
 2042 platform/text/QuotedPrintable.h \
20412043 platform/text/qt/TextCodecQt.h \
20422044 platform/text/RegularExpression.h \
20432045 platform/text/SegmentedString.h \

Source/WebCore/WebCore.vcproj/WebCore.vcproj

3052030520 RelativePath="..\platform\text\PlatformString.h"
3052130521 >
3052230522 </File>
 30523 <File
 30524 RelativePath="..\platform\text\QuotedPrintable.cpp"
 30525 >
 30526 </File>
 30527 <File
 30528 RelativePath="..\platform\text\QuotedPrintable.h"
 30529 >
 30530 </File>
3052330531 <File
3052430532 RelativePath="..\platform\text\RegularExpression.cpp"
3052530533 >

Source/WebCore/WebCore.xcodeproj/project.pbxproj

800800 379919961200DDF400EA041C /* WOFFFileFormat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379919941200DDF400EA041C /* WOFFFileFormat.cpp */; };
801801 379919971200DDF400EA041C /* WOFFFileFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 379919951200DDF400EA041C /* WOFFFileFormat.h */; };
802802 379919B21200DE5000EA041C /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 379919B11200DE5000EA041C /* libz.dylib */; };
 803 379E371613736A6600B9E919 /* QuotedPrintable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379E371413736A6600B9E919 /* QuotedPrintable.cpp */; };
 804 379E371713736A6600B9E919 /* QuotedPrintable.h in Headers */ = {isa = PBXBuildFile; fileRef = 379E371513736A6600B9E919 /* QuotedPrintable.h */; };
803805 379E61C9126CA5C300B63E8D /* BaseButtonInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379E61C5126CA5C300B63E8D /* BaseButtonInputType.cpp */; };
804806 379E61CA126CA5C400B63E8D /* BaseButtonInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = 379E61C6126CA5C300B63E8D /* BaseButtonInputType.h */; };
805807 379E61CB126CA5C400B63E8D /* BaseCheckableInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379E61C7126CA5C300B63E8D /* BaseCheckableInputType.cpp */; };

72417243 379919941200DDF400EA041C /* WOFFFileFormat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WOFFFileFormat.cpp; sourceTree = "<group>"; };
72427244 379919951200DDF400EA041C /* WOFFFileFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WOFFFileFormat.h; sourceTree = "<group>"; };
72437245 379919B11200DE5000EA041C /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = /usr/lib/libz.dylib; sourceTree = "<absolute>"; };
 7246 379E371413736A6600B9E919 /* QuotedPrintable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = QuotedPrintable.cpp; sourceTree = "<group>"; };
 7247 379E371513736A6600B9E919 /* QuotedPrintable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuotedPrintable.h; sourceTree = "<group>"; };
72447248 379E61C5126CA5C300B63E8D /* BaseButtonInputType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseButtonInputType.cpp; sourceTree = "<group>"; };
72457249 379E61C6126CA5C300B63E8D /* BaseButtonInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseButtonInputType.h; sourceTree = "<group>"; };
72467250 379E61C7126CA5C300B63E8D /* BaseCheckableInputType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseCheckableInputType.cpp; sourceTree = "<group>"; };

1773717741 F5142C68123F12B000F5BD4C /* LocalizedNumber.h */,
1773817742 BC76AC110DD7AD5C00415F34 /* ParserUtilities.h */,
1773917743 B2C3D9FB0D006C1D00EF6F26 /* PlatformString.h */,
 17744 379E371413736A6600B9E919 /* QuotedPrintable.cpp */,
 17745 379E371513736A6600B9E919 /* QuotedPrintable.h */,
1774017746 B2C3D9FC0D006C1D00EF6F26 /* RegularExpression.cpp */,
1774117747 B2C3D9FD0D006C1D00EF6F26 /* RegularExpression.h */,
1774217748 B2C3D9FE0D006C1D00EF6F26 /* SegmentedString.cpp */,

2273422740 E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
2273522741 977E2E0F12F0FC9C00C13379 /* XSSFilter.h in Headers */,
2273622742 37AFFDF71370A0B800E895C0 /* SharedBufferCRLFLineReader.h in Headers */,
 22743 379E371713736A6600B9E919 /* QuotedPrintable.h in Headers */,
2273722744 );
2273822745 runOnlyForDeploymentPostprocessing = 0;
2273922746 };

2539825405 E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
2539925406 977E2E0E12F0FC9C00C13379 /* XSSFilter.cpp in Sources */,
2540025407 37AFFDF61370A0B800E895C0 /* SharedBufferCRLFLineReader.cpp in Sources */,
 25408 379E371613736A6600B9E919 /* QuotedPrintable.cpp in Sources */,
2540125409 );
2540225410 runOnlyForDeploymentPostprocessing = 0;
2540325411 };

Source/WebCore/platform/text/QuotedPrintable.cpp

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions are
 6 * met:
 7 *
 8 * * Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * * Redistributions in binary form must reproduce the above
 11 * copyright notice, this list of conditions and the following disclaimer
 12 * in the documentation and/or other materials provided with the
 13 * distribution.
 14 * * Neither the name of Google Inc. nor the names of its
 15 * contributors may be used to endorse or promote products derived from
 16 * this software without specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29 */
 30
 31#include "config.h"
 32#include "QuotedPrintable.h"
 33
 34#include <wtf/ASCIICType.h>
 35
 36namespace WebCore {
 37
 38static const size_t maximumLineLength = 76;
 39
 40static const char crlfLineEnding[] = "\r\n";
 41
 42static size_t lengthOfLineEndingAtIndex(const char* input, size_t inputLength, size_t index)
 43{
 44 ASSERT(index < inputLength);
 45 if (input[index] == '\n')
 46 return 1; // Single LF.
 47
 48 if (input[index] == '\r') {
 49 if ((index + 1) == inputLength || input[index + 1] != '\n')
 50 return 1; // Single CR (Classic Mac OS).
 51 return 2; // CR-LF.
 52 }
 53
 54 return 0;
 55}
 56
 57void quotedPrintableEncode(const Vector<char>& in, Vector<char>& out)
 58{
 59 quotedPrintableEncode(in.data(), in.size(), out);
 60}
 61
 62void quotedPrintableEncode(const char* input, size_t inputLength, Vector<char>& out)
 63{
 64 out.clear();
 65 out.reserveCapacity(inputLength);
 66 size_t currentLineLength = 0;
 67 for (size_t i = 0; i < inputLength; ++i) {
 68 bool isLastCharacter = (i == inputLength - 1);
 69 char currentCharacter = input[i];
 70 bool requiresEncoding = false;
 71 // All non-printable ASCII characters and = require encoding.
 72 if ((currentCharacter < ' ' || currentCharacter > '~' || currentCharacter == '=') && currentCharacter != '\t')
 73 requiresEncoding = true;
 74
 75 // Space and tab characters have to be encoded if they appear at the end of a line.
 76 if (!requiresEncoding && (currentCharacter == '\t' || currentCharacter == ' ') && (isLastCharacter || lengthOfLineEndingAtIndex(input, inputLength, i + 1)))
 77 requiresEncoding = true;
 78
 79 // End of line should be converted to CR-LF sequences.
 80 if (!isLastCharacter) {
 81 size_t lengthOfLineEnding = lengthOfLineEndingAtIndex(input, inputLength, i);
 82 if (lengthOfLineEnding) {
 83 out.append(crlfLineEnding, strlen(crlfLineEnding));
 84 currentLineLength = 0;
 85 i += (lengthOfLineEnding - 1); // -1 because we'll ++ in the for() above.
 86 continue;
 87 }
 88 }
 89
 90 size_t lengthOfEncodedCharacter = 1;
 91 if (requiresEncoding)
 92 lengthOfEncodedCharacter += 2;
 93 if (!isLastCharacter)
 94 lengthOfEncodedCharacter += 1; // + 1 for the = (soft line break).
 95
 96 // Insert a soft line break if necessary.
 97 if (currentLineLength + lengthOfEncodedCharacter > maximumLineLength) {
 98 out.append('=');
 99 out.append(crlfLineEnding, strlen(crlfLineEnding));
 100 currentLineLength = 0;
 101 }
 102
 103 // Finally, insert the actual character(s).
 104 if (requiresEncoding) {
 105 out.append('=');
 106 out.append(upperNibbleToASCIIHexDigit(currentCharacter));
 107 out.append(lowerNibbleToASCIIHexDigit(currentCharacter));
 108 currentLineLength += 3;
 109 } else {
 110 out.append(currentCharacter);
 111 currentLineLength++;
 112 }
 113 }
 114}
 115
 116void quotedPrintableDecode(const Vector<char>& in, Vector<char>& out)
 117{
 118 quotedPrintableDecode(in.data(), in.size(), out);
 119}
 120
 121void quotedPrintableDecode(const char* data, size_t dataLength, Vector<char>& out)
 122{
 123 out.clear();
 124 if (!dataLength)
 125 return;
 126
 127 for (size_t i = 0; i < dataLength; ++i) {
 128 char currentCharacter = data[i];
 129 if (currentCharacter != '=') {
 130 out.append(currentCharacter);
 131 continue;
 132 }
 133 // We are dealing with a '=xx' sequence.
 134 if (dataLength - i < 3) {
 135 // Unfinished = sequence, append as is.
 136 out.append(currentCharacter);
 137 continue;
 138 }
 139 char upperCharacter = data[++i];
 140 char lowerCharacter = data[++i];
 141 if (upperCharacter == '\r' && lowerCharacter == '\n')
 142 continue;
 143
 144 if (!isASCIIHexDigit(upperCharacter) || !isASCIIHexDigit(lowerCharacter)) {
 145 // Invalid sequence, = followed by non hex digits, just insert the characters as is.
 146 out.append('=');
 147 out.append(upperCharacter);
 148 out.append(lowerCharacter);
 149 continue;
 150 }
 151 out.append(static_cast<char>(toASCIIHexValue(upperCharacter, lowerCharacter)));
 152 }
 153}
 154
 155}

Source/WebCore/platform/text/QuotedPrintable.h

 1/*
 2 * Copyright (C) 2011 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions are
 6 * met:
 7 *
 8 * * Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * * Redistributions in binary form must reproduce the above
 11 * copyright notice, this list of conditions and the following disclaimer
 12 * in the documentation and/or other materials provided with the
 13 * distribution.
 14 * * Neither the name of Google Inc. nor the names of its
 15 * contributors may be used to endorse or promote products derived from
 16 * this software without specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29 */
 30
 31#ifndef QuotedPrintable_h
 32#define QuotedPrintable_h
 33
 34#include <wtf/Vector.h>
 35
 36namespace WebCore {
 37
 38void quotedPrintableEncode(const Vector<char>&, Vector<char>&);
 39void quotedPrintableEncode(const char*, size_t, Vector<char>&);
 40
 41void quotedPrintableDecode(const Vector<char>&, Vector<char>&);
 42void quotedPrintableDecode(const char*, size_t, Vector<char>&);
 43
 44} // namespace WebCore
 45
 46#endif // QuotedPrintable_h