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

Side by Side Diff: Source/weborigin/KURL.cpp

Issue 24095009: KURL not handling NULL m_string members properly. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: avoid duplicate check in initProtocolIsInHTTPFamily() Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/weborigin/KURLTest.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) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
4 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. 4 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 { 290 {
291 // Note that http://www.google.com/" has a path, the path is "/". This can 291 // Note that http://www.google.com/" has a path, the path is "/". This can
292 // return false only for invalid or nonstandard URLs. 292 // return false only for invalid or nonstandard URLs.
293 return m_parsed.path.len >= 0; 293 return m_parsed.path.len >= 0;
294 } 294 }
295 295
296 // We handle "parameters" separated by a semicolon, while KURL.cpp does not, 296 // We handle "parameters" separated by a semicolon, while KURL.cpp does not,
297 // which can lead to different results in some cases. 297 // which can lead to different results in some cases.
298 String KURL::lastPathComponent() const 298 String KURL::lastPathComponent() const
299 { 299 {
300 if (!m_isValid) 300 if (m_string.isNull() || !m_isValid)
abarth-chromium 2013/09/17 19:57:02 I don't understand why this change is needed. If
301 return stringForInvalidComponent(); 301 return stringForInvalidComponent();
302 302
303 // When the output ends in a slash, WebCore has different expectations than 303 // When the output ends in a slash, WebCore has different expectations than
304 // the GoogleURL library. For "/foo/bar/" the library will return the empty 304 // the GoogleURL library. For "/foo/bar/" the library will return the empty
305 // string, but WebCore wants "bar". 305 // string, but WebCore wants "bar".
306 url_parse::Component path = m_parsed.path; 306 url_parse::Component path = m_parsed.path;
307 if (path.len > 0 && m_string[path.end() - 1] == '/') 307 if (path.len > 0 && m_string[path.end() - 1] == '/')
308 path.len--; 308 path.len--;
309 309
310 url_parse::Component file; 310 url_parse::Component file;
311 if (!m_string.isNull() && m_string.is8Bit()) 311 if (m_string.is8Bit())
312 url_parse::ExtractFileName(asURLChar8Subtle(m_string), path, &file); 312 url_parse::ExtractFileName(asURLChar8Subtle(m_string), path, &file);
313 else 313 else
314 url_parse::ExtractFileName(m_string.characters16(), path, &file); 314 url_parse::ExtractFileName(m_string.characters16(), path, &file);
315 315
316 // Bug: https://bugs.webkit.org/show_bug.cgi?id=21015 this function returns 316 // Bug: https://bugs.webkit.org/show_bug.cgi?id=21015 this function returns
317 // a null string when the path is empty, which we duplicate here. 317 // a null string when the path is empty, which we duplicate here.
318 if (!file.is_nonempty()) 318 if (!file.is_nonempty())
319 return String(); 319 return String();
320 return componentString(file); 320 return componentString(file);
321 } 321 }
322 322
323 String KURL::protocol() const 323 String KURL::protocol() const
324 { 324 {
325 return componentString(m_parsed.scheme); 325 return componentString(m_parsed.scheme);
326 } 326 }
327 327
328 String KURL::host() const 328 String KURL::host() const
329 { 329 {
330 return componentString(m_parsed.host); 330 return componentString(m_parsed.host);
331 } 331 }
332 332
333 // Returns 0 when there is no port. 333 // Returns 0 when there is no port.
334 // 334 //
335 // We treat URL's with out-of-range port numbers as invalid URLs, and they will 335 // We treat URL's with out-of-range port numbers as invalid URLs, and they will
336 // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but 336 // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but
337 // return invalidPortNumber from this port() function, so we mirror that behavio r here. 337 // return invalidPortNumber from this port() function, so we mirror that behavio r here.
338 unsigned short KURL::port() const 338 unsigned short KURL::port() const
339 { 339 {
340 if (!m_isValid || m_parsed.port.len <= 0) 340 if (m_string.isNull() || !m_isValid || m_parsed.port.len <= 0)
341 return 0; 341 return 0;
342 int port = 0; 342 int port = m_string.is8Bit() ?
343 if (!m_string.isNull() && m_string.is8Bit()) 343 url_parse::ParsePort(asURLChar8Subtle(m_string), m_parsed.port) :
344 port = url_parse::ParsePort(asURLChar8Subtle(m_string), m_parsed.port); 344 url_parse::ParsePort(m_string.characters16(), m_parsed.port);
345 else
346 port = url_parse::ParsePort(m_string.characters16(), m_parsed.port);
347 ASSERT(port != url_parse::PORT_UNSPECIFIED); // Checked port.len <= 0 before . 345 ASSERT(port != url_parse::PORT_UNSPECIFIED); // Checked port.len <= 0 before .
348 346
349 if (port == url_parse::PORT_INVALID || port > maximumValidPortNumber) // Mim ic KURL::port() 347 if (port == url_parse::PORT_INVALID || port > maximumValidPortNumber) // Mim ic KURL::port()
350 port = invalidPortNumber; 348 port = invalidPortNumber;
351 349
352 return static_cast<unsigned short>(port); 350 return static_cast<unsigned short>(port);
353 } 351 }
354 352
355 String KURL::pass() const 353 String KURL::pass() const
356 { 354 {
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 615
618 url_util::EncodeURIComponent(utf8.data(), inputLength, &buffer); 616 url_util::EncodeURIComponent(utf8.data(), inputLength, &buffer);
619 String escaped(buffer.data(), buffer.length()); 617 String escaped(buffer.data(), buffer.length());
620 // Unescape '/'; it's safe and much prettier. 618 // Unescape '/'; it's safe and much prettier.
621 escaped.replace("%2F", "/"); 619 escaped.replace("%2F", "/");
622 return escaped; 620 return escaped;
623 } 621 }
624 622
625 bool KURL::isHierarchical() const 623 bool KURL::isHierarchical() const
626 { 624 {
627 if (!m_parsed.scheme.is_nonempty()) 625 if (m_string.isNull() || !m_parsed.scheme.is_nonempty())
628 return false; 626 return false;
629 if (!m_string.isNull() && m_string.is8Bit()) 627
630 return url_util::IsStandard(asURLChar8Subtle(m_string), m_parsed.scheme) ; 628 return m_string.is8Bit() ?
631 return url_util::IsStandard(m_string.characters16(), m_parsed.scheme); 629 url_util::IsStandard(asURLChar8Subtle(m_string), m_parsed.scheme) :
630 url_util::IsStandard(m_string.characters16(), m_parsed.scheme);
632 } 631 }
633 632
634 #ifndef NDEBUG 633 #ifndef NDEBUG
635 void KURL::print() const 634 void KURL::print() const
636 { 635 {
637 printf("%s\n", m_string.utf8().data()); 636 printf("%s\n", m_string.utf8().data());
638 } 637 }
639 #endif 638 #endif
640 639
641 bool equalIgnoringFragmentIdentifier(const KURL& a, const KURL& b) 640 bool equalIgnoringFragmentIdentifier(const KURL& a, const KURL& b)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false); 678 return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false);
680 } 679 }
681 680
682 unsigned KURL::pathEnd() const 681 unsigned KURL::pathEnd() const
683 { 682 {
684 return m_parsed.CountCharactersBefore(url_parse::Parsed::QUERY, true); 683 return m_parsed.CountCharactersBefore(url_parse::Parsed::QUERY, true);
685 } 684 }
686 685
687 unsigned KURL::pathAfterLastSlash() const 686 unsigned KURL::pathAfterLastSlash() const
688 { 687 {
688 if (m_string.isNull())
689 return 0;
689 if (!m_isValid || !m_parsed.path.is_valid()) 690 if (!m_isValid || !m_parsed.path.is_valid())
690 return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false); 691 return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false);
691
692 url_parse::Component filename; 692 url_parse::Component filename;
693 if (!m_string.isNull() && m_string.is8Bit()) 693 if (m_string.is8Bit())
694 url_parse::ExtractFileName(asURLChar8Subtle(m_string), m_parsed.path, &f ilename); 694 url_parse::ExtractFileName(asURLChar8Subtle(m_string), m_parsed.path, &f ilename);
695 else 695 else
696 url_parse::ExtractFileName(m_string.characters16(), m_parsed.path, &file name); 696 url_parse::ExtractFileName(m_string.characters16(), m_parsed.path, &file name);
697 return filename.begin; 697 return filename.begin;
698 } 698 }
699 699
700 bool protocolIs(const String& url, const char* protocol) 700 bool protocolIs(const String& url, const char* protocol)
701 { 701 {
702 assertProtocolIsGood(protocol); 702 assertProtocolIsGood(protocol);
703 if (url.isNull()) 703 if (url.isNull())
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 return false; 781 return false;
782 } 782 }
783 783
784 void KURL::initProtocolIsInHTTPFamily() 784 void KURL::initProtocolIsInHTTPFamily()
785 { 785 {
786 if (!m_isValid) { 786 if (!m_isValid) {
787 m_protocolIsInHTTPFamily = false; 787 m_protocolIsInHTTPFamily = false;
788 return; 788 return;
789 } 789 }
790 790
791 if (!m_string.isNull() && m_string.is8Bit()) 791 ASSERT(!m_string.isNull());
792 m_protocolIsInHTTPFamily = checkIfProtocolIsInHTTPFamily(m_parsed.scheme , m_string.characters8()); 792 m_protocolIsInHTTPFamily = m_string.is8Bit() ?
793 else 793 checkIfProtocolIsInHTTPFamily(m_parsed.scheme, m_string.characters8()) :
794 m_protocolIsInHTTPFamily = checkIfProtocolIsInHTTPFamily(m_parsed.scheme , m_string.characters16()); 794 checkIfProtocolIsInHTTPFamily(m_parsed.scheme, m_string.characters16());
795 } 795 }
796 796
797 bool KURL::protocolIs(const char* protocol) const 797 bool KURL::protocolIs(const char* protocol) const
798 { 798 {
799 assertProtocolIsGood(protocol); 799 assertProtocolIsGood(protocol);
800 800
801 // JavaScript URLs are "valid" and should be executed even if KURL decides t hey are invalid. 801 // JavaScript URLs are "valid" and should be executed even if KURL decides t hey are invalid.
802 // The free function protocolIsJavaScript() should be used instead. 802 // The free function protocolIsJavaScript() should be used instead.
803 // FIXME: Chromium code needs to be fixed for this assert to be enabled. ASS ERT(strcmp(protocol, "javascript")); 803 // FIXME: Chromium code needs to be fixed for this assert to be enabled. ASS ERT(strcmp(protocol, "javascript"));
804 804
805 if (m_parsed.scheme.len <= 0) 805 if (m_string.isNull() || m_parsed.scheme.len <= 0)
806 return !protocol; 806 return *protocol == '\0';
807 if (!m_string.isNull() && m_string.is8Bit()) 807
808 return internalProtocolIs(m_parsed.scheme, m_string.characters8(), proto col); 808 return m_string.is8Bit() ?
809 return internalProtocolIs(m_parsed.scheme, m_string.characters16(), protocol ); 809 internalProtocolIs(m_parsed.scheme, m_string.characters8(), protocol) :
810 internalProtocolIs(m_parsed.scheme, m_string.characters16(), protocol);
810 } 811 }
811 812
812 String KURL::stringForInvalidComponent() const 813 String KURL::stringForInvalidComponent() const
813 { 814 {
814 if (m_string.isNull()) 815 if (m_string.isNull())
815 return String(); 816 return String();
816 return emptyString(); 817 return emptyString();
817 } 818 }
818 819
819 String KURL::componentString(const url_parse::Component& component) const 820 String KURL::componentString(const url_parse::Component& component) const
(...skipping 24 matching lines...) Expand all
844 m_string = AtomicString::fromUTF8(output.data(), output.length()); 845 m_string = AtomicString::fromUTF8(output.data(), output.length());
845 } 846 }
846 847
847 bool KURL::isSafeToSendToAnotherThread() const 848 bool KURL::isSafeToSendToAnotherThread() const
848 { 849 {
849 return m_string.isSafeToSendToAnotherThread() 850 return m_string.isSafeToSendToAnotherThread()
850 && (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread()); 851 && (!m_innerURL || m_innerURL->isSafeToSendToAnotherThread());
851 } 852 }
852 853
853 } // namespace WebCore 854 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/weborigin/KURLTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698