Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: third_party/WebKit/Source/core/css/CSSMarkup.cpp

Issue 1498473004: CSS.escape('\0') should not throw. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding idl file changes Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 appendTo.append(c); 193 appendTo.append(c);
194 } 194 }
195 195
196 static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo) 196 static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo)
197 { 197 {
198 appendTo.append('\\'); 198 appendTo.append('\\');
199 appendUnsignedAsHex(c, appendTo, Lowercase); 199 appendUnsignedAsHex(c, appendTo, Lowercase);
200 appendTo.append(' '); 200 appendTo.append(' ');
201 } 201 }
202 202
203 bool serializeIdentifier(const String& identifier, StringBuilder& appendTo) 203 void serializeIdentifier(const String& identifier, StringBuilder& appendTo)
204 { 204 {
205 bool isFirst = true; 205 bool isFirst = true;
206 bool isSecond = false; 206 bool isSecond = false;
207 bool isFirstCharHyphen = false; 207 bool isFirstCharHyphen = false;
208 unsigned index = 0; 208 unsigned index = 0;
209 while (index < identifier.length()) { 209 while (index < identifier.length()) {
210 UChar32 c = identifier.characterStartingAt(index); 210 UChar32 c = identifier.characterStartingAt(index);
211 if (c == 0) { 211 if (c == 0) {
212 // Check for lone surrogate which characterStartingAt does not retur n. 212 // Check for lone surrogate which characterStartingAt does not retur n.
213 c = identifier[index]; 213 c = identifier[index];
214 if (c == 0)
215 return false;
216 } 214 }
217 215
218 index += U16_LENGTH(c); 216 index += U16_LENGTH(c);
219 217
220 if (c <= 0x1f || c == 0x7f || (0x30 <= c && c <= 0x39 && (isFirst || (is Second && isFirstCharHyphen)))) 218 if (c == 0)
219 appendTo.append(0xfffd);
220 else if (c <= 0x1f || c == 0x7f || (0x30 <= c && c <= 0x39 && (isFirst | | (isSecond && isFirstCharHyphen))))
221 serializeCharacterAsCodePoint(c, appendTo); 221 serializeCharacterAsCodePoint(c, appendTo);
222 else if (c == 0x2d && isFirst && index == identifier.length()) 222 else if (c == 0x2d && isFirst && index == identifier.length())
223 serializeCharacter(c, appendTo); 223 serializeCharacter(c, appendTo);
224 else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a)) 224 else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a))
225 appendTo.append(c); 225 appendTo.append(c);
226 else 226 else
227 serializeCharacter(c, appendTo); 227 serializeCharacter(c, appendTo);
228 228
229 if (isFirst) { 229 if (isFirst) {
230 isFirst = false; 230 isFirst = false;
231 isSecond = true; 231 isSecond = true;
232 isFirstCharHyphen = (c == 0x2d); 232 isFirstCharHyphen = (c == 0x2d);
233 } else if (isSecond) { 233 } else if (isSecond) {
234 isSecond = false; 234 isSecond = false;
235 } 235 }
236 } 236 }
237 return true;
238 } 237 }
239 238
240 void serializeString(const String& string, StringBuilder& appendTo) 239 void serializeString(const String& string, StringBuilder& appendTo)
241 { 240 {
242 appendTo.append('\"'); 241 appendTo.append('\"');
243 242
244 unsigned index = 0; 243 unsigned index = 0;
245 while (index < string.length()) { 244 while (index < string.length()) {
246 UChar32 c = string.characterStartingAt(index); 245 UChar32 c = string.characterStartingAt(index);
247 index += U16_LENGTH(c); 246 index += U16_LENGTH(c);
(...skipping 14 matching lines...) Expand all
262 serializeString(string, builder); 261 serializeString(string, builder);
263 return builder.toString(); 262 return builder.toString();
264 } 263 }
265 264
266 String serializeURI(const String& string) 265 String serializeURI(const String& string)
267 { 266 {
268 return "url(" + serializeString(string) + ")"; 267 return "url(" + serializeString(string) + ")";
269 } 268 }
270 269
271 } // namespace blink 270 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSMarkup.h ('k') | third_party/WebKit/Source/core/css/DOMWindowCSS.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698