Changeset 69072 in webkit
- Timestamp:
- Oct 4, 2010 10:06:00 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r69068 r69072 1 2010-10-04 Patrick Gansterer <paroga@paroga.com> 2 3 Reviewed by Darin Adler. 4 5 Add Base64DecodePolicy option at base64Decode() 6 https://bugs.webkit.org/show_bug.cgi?id=41510 7 8 * fast/dom/Window/atob-btoa-expected.txt: 9 * fast/dom/Window/atob-btoa.html: 10 * platform/mac/fast/loader/user-stylesheet-fast-path-expected.txt: 11 * platform/mac/fast/loader/user-stylesheet-fast-path.html: Added additional data urls tests. 12 1 13 2010-10-04 Yael Aharon <yael.aharon@nokia.com> 2 14 -
trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt
r55637 r69072 36 36 PASS window.atob("zz") is "Ï" 37 37 PASS window.atob("zzz") is "Ï<" 38 PASS window.atob("zzz=") is "Ï<" 39 PASS window.atob("zzz==") is "Ï<" 40 PASS window.atob("zzz===") is "Ï<" 41 PASS window.atob("zzz====") is "Ï<" 38 42 PASS window.atob("zzzz") is "Ï<ó" 39 43 PASS window.atob("zzzzz") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 44 PASS window.atob("z=zz") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 40 45 PASS window.atob("=") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. 41 46 PASS window.atob("==") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5. -
trunk/LayoutTests/fast/dom/Window/atob-btoa.html
r55637 r69072 49 49 shouldBe('window.atob("zz")', '"Ï"'); 50 50 shouldBe('window.atob("zzz")', '"Ï\u003C"'); 51 shouldBe('window.atob("zzz=")', '"Ï\u003C"'); 52 shouldBe('window.atob("zzz==")', '"Ï\u003C"'); 53 shouldBe('window.atob("zzz===")', '"Ï\u003C"'); 54 shouldBe('window.atob("zzz====")', '"Ï\u003C"'); 51 55 shouldBe('window.atob("zzzz")', '"Ï\u003Có"'); 52 56 shouldThrow('window.atob("zzzzz")'); 57 shouldThrow('window.atob("z=zz")'); 53 58 shouldThrow('window.atob("=")'); 54 59 shouldThrow('window.atob("==")'); -
trunk/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path-expected.txt
r67642 r69072 2 2 3 3 PASS 100px 4 PASS 110px 5 PASS 120px 6 PASS 130px 4 7 PASS 140px 5 8 PASS 150px -
trunk/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path.html
r67642 r69072 7 7 var testObjects = [ 8 8 {result:true, size:"100px", url:"data:text/css;charset=utf-8;base64,Ym9keSB7Zm9udC1zaXplOiAxMDBweH0="}, 9 {result:true, size:"110px", url:encodeURI("data:text/css;charset=utf-8;base64, Ym9keSB7Zm9udC1zaXplOiAxMTBweH0= ")}, 10 {result:true, size:"120px", url:encodeURI("data:text/css;charset=utf-8;base64,\n \r \t Ym9k \t eSB7 \r Zm9ud \n \n C1zaXp \r lOiAxM \t jBweH0= \t \r \n")}, 11 {result:true, size:"130px", url:encodeURI("data:text/css;charset=utf-8;base64,\u0059 \u006D \u0039 \u006B eSB7Zm9ud C1zaXplOiAxMzBwe \u0048 \u0030 \u003D")}, 9 12 {result:false, size:"140px", url:"data:text/css;charset=utf-8;base64,Ym9k$#eSB7Zm#9ud(C1zaXp)lOiAxNDBweH0="}, 10 13 {result:false, size:"150px", url:"data:text/css;charset=utf-8;base64,Ym9ke%00SB7Z%20m9udC1z\n\taXplO#iAx%03NTBw%eH0="}, -
trunk/WebCore/ChangeLog
r69071 r69072 1 2010-10-04 Patrick Gansterer <paroga@paroga.com> 2 3 Reviewed by Darin Adler. 4 5 Add Base64DecodePolicy option at base64Decode() 6 https://bugs.webkit.org/show_bug.cgi?id=41510 7 8 Add an option for ignoring characters in base64 data. 9 This is necessary for decoding data urls. 10 11 Also add an overload to decode WebCore::String directly. 12 13 * page/DOMWindow.cpp: 14 (WebCore::DOMWindow::atob): 15 * page/Page.cpp: 16 (WebCore::Page::userStyleSheetLocationChanged): 17 * platform/text/Base64.cpp: 18 (WebCore::base64Encode): 19 (WebCore::base64Decode): 20 (WebCore::base64DecodeInternal): 21 * platform/text/Base64.h: 22 (WebCore::): 23 1 24 2010-10-04 Ryuan Choi <bunhere@gmail.com> 2 25 -
trunk/WebCore/page/DOMWindow.cpp
r68440 r69072 994 994 } 995 995 996 Vector<char> in;997 in.append(encodedString.characters(), encodedString.length());998 996 Vector<char> out; 999 1000 if (!base64Decode(in, out)) { 997 if (!base64Decode(encodedString, out, FailOnInvalidCharacter)) { 1001 998 ec = INVALID_CHARACTER_ERR; 1002 999 return String(); -
trunk/WebCore/page/Page.cpp
r69053 r69072 636 636 m_userStyleSheet = String(); 637 637 m_userStyleSheetModificationTime = 0; 638 638 639 639 // Data URLs with base64-encoded UTF-8 style sheets are common. We can process them 640 640 // synchronously and avoid using a loader. 641 641 if (url.protocolIs("data") && url.string().startsWith("data:text/css;charset=utf-8;base64,")) { 642 642 m_didLoadUserStyleSheet = true; 643 644 const unsigned prefixLength = 35;645 Vector<char> encodedData(url.string().length() - prefixLength);646 for (unsigned i = prefixLength; i < url.string().length(); ++i)647 encodedData[i - prefixLength] = static_cast<char>(url.string()[i]);648 643 649 644 Vector<char> styleSheetAsUTF8; 650 if (base64Decode( encodedData, styleSheetAsUTF8))645 if (base64Decode(decodeURLEscapeSequences(url.string().substring(35)), styleSheetAsUTF8, IgnoreWhitespace)) 651 646 m_userStyleSheet = String::fromUTF8(styleSheetAsUTF8.data(), styleSheetAsUTF8.size()); 652 647 } 653 648 654 649 for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) { 655 650 if (frame->document()) -
trunk/WebCore/platform/text/Base64.cpp
r55633 r69072 3 3 Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 4 4 Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 5 Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> 5 6 6 7 This program is free software; you can redistribute it and/or modify … … 26 27 #include <limits.h> 27 28 #include <wtf/StringExtras.h> 29 #include <wtf/text/WTFString.h> 28 30 29 31 namespace WebCore { … … 71 73 72 74 // If the input string is pathologically large, just return nothing. 73 // Note: Keep this in sync with the "out _len" computation below.75 // Note: Keep this in sync with the "outLength" computation below. 74 76 // Rather than being perfectly precise, this is a bit conservative. 75 77 const unsigned maxInputBufferSize = UINT_MAX / 77 * 76 / 4 * 3 - 2; … … 80 82 unsigned didx = 0; 81 83 82 unsigned out _len= ((len + 2) / 3) * 4;84 unsigned outLength = ((len + 2) / 3) * 4; 83 85 84 86 // Deal with the 76 character per line limit specified in RFC 2045. 85 insertLFs = (insertLFs && out _len> 76);87 insertLFs = (insertLFs && outLength > 76); 86 88 if (insertLFs) 87 out _len += ((out_len- 1) / 76);89 outLength += ((outLength - 1) / 76); 88 90 89 91 int count = 0; 90 out.grow(out _len);92 out.grow(outLength); 91 93 92 94 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion … … 94 96 while (sidx < len - 2) { 95 97 if (insertLFs) { 96 if (count && (count % 76) == 0)98 if (count && !(count % 76)) 97 99 out[didx++] = '\n'; 98 100 count += 4; … … 107 109 108 110 if (sidx < len) { 109 if (insertLFs && (count > 0) && (count % 76) == 0)111 if (insertLFs && (count > 0) && !(count % 76)) 110 112 out[didx++] = '\n'; 111 113 … … 125 127 } 126 128 127 bool base64Decode(const Vector<char>& in, Vector<char>& out )129 bool base64Decode(const Vector<char>& in, Vector<char>& out, Base64DecodePolicy policy) 128 130 { 129 131 out.clear(); … … 133 135 return false; 134 136 135 return base64Decode(in.data(), in.size(), out); 136 } 137 138 bool base64Decode(const char* data, unsigned len, Vector<char>& out) 137 return base64Decode(in.data(), in.size(), out, policy); 138 } 139 140 template<typename T> 141 static inline bool base64DecodeInternal(const T* data, unsigned len, Vector<char>& out, Base64DecodePolicy policy) 139 142 { 140 143 out.clear(); 141 if ( len == 0)144 if (!len) 142 145 return true; 143 146 144 while (len && data[len-1] == '=')145 --len;146 147 147 out.grow(len); 148 149 bool sawEqualsSign = false; 150 unsigned outLength = 0; 148 151 for (unsigned idx = 0; idx < len; idx++) { 149 unsigned char ch = data[idx]; 150 if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) || (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=') 151 out[idx] = base64DecMap[ch]; 152 else 152 unsigned ch = data[idx]; 153 if (ch == '=') 154 sawEqualsSign = true; 155 else if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ch == '+' || ch == '/') { 156 if (sawEqualsSign) 157 return false; 158 out[outLength] = base64DecMap[ch]; 159 outLength++; 160 } else if (policy == FailOnInvalidCharacter || (policy == IgnoreWhitespace && !isSpaceOrNewline(ch))) 153 161 return false; 154 162 } 155 163 164 if (!outLength) 165 return !sawEqualsSign; 166 167 // Valid data is (n * 4 + [0,2,3]) characters long. 168 if ((outLength % 4) == 1) 169 return false; 170 156 171 // 4-byte to 3-byte conversion 157 unsigned outLen = len - ((len + 3) / 4);158 if (!outLen || ((outLen + 2) / 3) * 4 < len)172 outLength -= (outLength + 3) / 4; 173 if (!outLength) 159 174 return false; 160 175 161 176 unsigned sidx = 0; 162 177 unsigned didx = 0; 163 if (outLen > 1) {164 while (didx < outLen - 2) {178 if (outLength > 1) { 179 while (didx < outLength - 2) { 165 180 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003)); 166 181 out[didx + 1] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017)); … … 171 186 } 172 187 173 if (didx < outLen )188 if (didx < outLength) 174 189 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003)); 175 190 176 if (++didx < outLen )191 if (++didx < outLength) 177 192 out[didx] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017)); 178 193 179 if (outLen < out.size())180 out.shrink(outLen );194 if (outLength < out.size()) 195 out.shrink(outLength); 181 196 182 197 return true; 183 198 } 184 199 185 } 200 bool base64Decode(const char* data, unsigned len, Vector<char>& out, Base64DecodePolicy policy) 201 { 202 return base64DecodeInternal<char>(data, len, out, policy); 203 } 204 205 bool base64Decode(const String& in, Vector<char>& out, Base64DecodePolicy policy) 206 { 207 return base64DecodeInternal<UChar>(in.characters(), in.length(), out, policy); 208 } 209 210 } // namespace WebCore -
trunk/WebCore/platform/text/Base64.h
r54616 r69072 1 1 /* 2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 2 * Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 27 28 #define Base64_h 28 29 30 #include <wtf/Forward.h> 29 31 #include <wtf/Vector.h> 30 32 31 33 namespace WebCore { 32 34 35 enum Base64DecodePolicy { FailOnInvalidCharacter, IgnoreWhitespace, IgnoreInvalidCharacters }; 36 33 37 void base64Encode(const Vector<char>&, Vector<char>&, bool insertLFs = false); 34 38 void base64Encode(const char*, unsigned, Vector<char>&, bool insertLFs = false); 35 39 36 // this decoder is not general purpose - it returns an error if it encounters a linefeed, as needed for window.atob 37 bool base64Decode(const Vector<char>&, Vector<char>& );38 bool base64Decode(const char*, unsigned, Vector<char>& );40 bool base64Decode(const String&, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter); 41 bool base64Decode(const Vector<char>&, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter); 42 bool base64Decode(const char*, unsigned, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter); 39 43 40 44 }
Note: See TracChangeset
for help on using the changeset viewer.