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

Side by Side Diff: Source/core/dom/DOMImplementation.cpp

Issue 122743002: MIME type predicates and case-insensitive matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Disambiguate char/UChar comparison Created 6 years, 11 months 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
« no previous file with comments | « Source/core/dom/DOMImplementation.h ('k') | Source/core/dom/DOMImplementationTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * Copyright (C) 2006 Samuel Weinig (sam@webkit.org) 6 * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 PassRefPtr<CSSStyleSheet> DOMImplementation::createCSSStyleSheet(const String&, const String& media) 227 PassRefPtr<CSSStyleSheet> DOMImplementation::createCSSStyleSheet(const String&, const String& media)
228 { 228 {
229 // FIXME: Title should be set. 229 // FIXME: Title should be set.
230 // FIXME: Media could have wrong syntax, in which case we should generate an exception. 230 // FIXME: Media could have wrong syntax, in which case we should generate an exception.
231 RefPtr<CSSStyleSheet> sheet = CSSStyleSheet::create(StyleSheetContents::crea te()); 231 RefPtr<CSSStyleSheet> sheet = CSSStyleSheet::create(StyleSheetContents::crea te());
232 sheet->setMediaQueries(MediaQuerySet::create(media)); 232 sheet->setMediaQueries(MediaQuerySet::create(media));
233 return sheet; 233 return sheet;
234 } 234 }
235 235
236 static bool equalToUpperCaseASCIIIgnoringCase(char asciiUpper, UChar u)
237 {
238 return static_cast<UChar>(asciiUpper) == (u & static_cast<UChar>(~0x20));
jochen (gone - plz use gerrit) 2014/01/03 11:31:09 nit. use toASCIIUpper()
239 }
240
236 bool DOMImplementation::isXMLMIMEType(const String& mimeType) 241 bool DOMImplementation::isXMLMIMEType(const String& mimeType)
237 { 242 {
238 if (mimeType == "text/xml" || mimeType == "application/xml" || mimeType == " text/xsl") 243 if (equalIgnoringCase(mimeType, "text/xml")
244 || equalIgnoringCase(mimeType, "application/xml")
245 || equalIgnoringCase(mimeType, "text/xsl"))
239 return true; 246 return true;
240 247
241 // Per RFCs 3023 and 2045 a mime type is of the form: 248 // Per RFCs 3023 and 2045, an XML MIME type is of the form:
242 // ^[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]+/[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]+\+xml $ 249 // ^[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]+/[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]+\+xml $
243 250
244 int length = mimeType.length(); 251 int length = mimeType.length();
245 if (length < 7) 252 if (length < 7)
246 return false; 253 return false;
247 254
248 if (mimeType[0] == '/' || 255 if (mimeType[0] == '/'
249 mimeType[length - 5] == '/' || 256 || mimeType[length - 5] == '/'
250 mimeType[length - 4] != '+' || 257 || mimeType[length - 4] != '+'
251 mimeType[length - 3] != 'x' || 258 || !equalToUpperCaseASCIIIgnoringCase('X', mimeType[length - 3])
jochen (gone - plz use gerrit) 2014/01/03 11:31:09 why not !mimeType.endsWith("+xml", true)
sof 2014/01/03 13:51:02 Nice; switched to this simpler form instead (remov
252 mimeType[length - 2] != 'm' || 259 || !equalToUpperCaseASCIIIgnoringCase('M', mimeType[length - 2])
253 mimeType[length - 1] != 'l') 260 || !equalToUpperCaseASCIIIgnoringCase('L', mimeType[length - 1]))
254 return false; 261 return false;
255 262
256 bool hasSlash = false; 263 bool hasSlash = false;
257 for (int i = 0; i < length - 4; ++i) { 264 for (int i = 0; i < length - 4; ++i) {
258 UChar ch = mimeType[i]; 265 UChar ch = mimeType[i];
259 if (ch >= '0' && ch <= '9') 266 if (ch >= '0' && ch <= '9')
260 continue; 267 continue;
261 if (ch >= 'a' && ch <= 'z') 268 if (ch >= 'a' && ch <= 'z')
262 continue; 269 continue;
263 if (ch >= 'A' && ch <= 'Z') 270 if (ch >= 'A' && ch <= 'Z')
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 return TextDocument::create(init); 387 return TextDocument::create(init);
381 if (type == "image/svg+xml") 388 if (type == "image/svg+xml")
382 return SVGDocument::create(init); 389 return SVGDocument::create(init);
383 if (isXMLMIMEType(type)) 390 if (isXMLMIMEType(type))
384 return Document::create(init); 391 return Document::create(init);
385 392
386 return HTMLDocument::create(init); 393 return HTMLDocument::create(init);
387 } 394 }
388 395
389 } 396 }
OLDNEW
« no previous file with comments | « Source/core/dom/DOMImplementation.h ('k') | Source/core/dom/DOMImplementationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698