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

Side by Side Diff: src/url_canon_unittest.cc

Issue 2027007: Fix a crash in IP address checking because the boundary case for an empty or ... (Closed) Base URL: http://google-url.googlecode.com/svn/trunk/
Patch Set: Created 10 years, 7 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
« src/url_canon_ip.cc ('K') | « src/url_canon_ip.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007, Google Inc. 1 // Copyright 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 std::string out_str2; 754 std::string out_str2;
755 url_canon::StdStringCanonOutput output2(&out_str2); 755 url_canon::StdStringCanonOutput output2(&out_str2);
756 url_canon::CanonicalizeIPAddress(input16.c_str(), component, &output2, 756 url_canon::CanonicalizeIPAddress(input16.c_str(), component, &output2,
757 &host_info); 757 &host_info);
758 output2.Complete(); 758 output2.Complete();
759 759
760 EXPECT_EQ(cases[i].expected_family, host_info.family); 760 EXPECT_EQ(cases[i].expected_family, host_info.family);
761 if (host_info.family == CanonHostInfo::IPV6) { 761 if (host_info.family == CanonHostInfo::IPV6) {
762 EXPECT_STREQ(cases[i].expected, out_str2.c_str()); 762 EXPECT_STREQ(cases[i].expected, out_str2.c_str());
763 EXPECT_EQ(cases[i].expected_component.begin, host_info.out_host.begin); 763 EXPECT_EQ(cases[i].expected_component.begin, host_info.out_host.begin);
764 EXPECT_EQ(cases[i].expected_component.len, host_info.out_host.len); 764 EXPECT_EQ(cases[i].expected_compo nent.len, host_info.out_host.len);
765 } 765 }
766 } 766 }
767 } 767 }
768 768
769 TEST(URLCanonTest, IPEmpty) {
770 std::string out_str1;
771 url_canon::StdStringCanonOutput output1(&out_str1);
772 url_canon::CanonHostInfo host_info;
773
774 // This tests tests.
775 const char spec[] = "192.168.0.1";
776 url_canon::CanonicalizeIPAddress(spec, url_parse::Component(),
777 &output1, &host_info);
778 EXPECT_FALSE(host_info.IsIPAddress());
779
780 url_canon::CanonicalizeIPAddress(spec, url_parse::Component(0, 0),
781 &output1, &host_info);
782 EXPECT_FALSE(host_info.IsIPAddress());
783 }
784
769 TEST(URLCanonTest, UserInfo) { 785 TEST(URLCanonTest, UserInfo) {
770 // Note that the canonicalizer should escape and treat empty components as 786 // Note that the canonicalizer should escape and treat empty components as
771 // not being there. 787 // not being there.
772 788
773 // We actually parse a full input URL so we can get the initial components. 789 // We actually parse a full input URL so we can get the initial components.
774 struct UserComponentCase { 790 struct UserComponentCase {
775 const char* input; 791 const char* input;
776 const char* expected; 792 const char* expected;
777 url_parse::Component expected_username; 793 url_parse::Component expected_username;
778 url_parse::Component expected_password; 794 url_parse::Component expected_password;
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 url_canon::StdStringCanonOutput repl_output(&repl_str); 1946 url_canon::StdStringCanonOutput repl_output(&repl_str);
1931 url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed) ; 1947 url_canon::ReplaceFileURL(src, parsed, repl, NULL, &repl_output, &repl_parsed) ;
1932 repl_output.Complete(); 1948 repl_output.Complete();
1933 1949
1934 // Generate the expected string and check. 1950 // Generate the expected string and check.
1935 std::string expected("file:///foo?"); 1951 std::string expected("file:///foo?");
1936 for (size_t i = 0; i < new_query.length(); i++) 1952 for (size_t i = 0; i < new_query.length(); i++)
1937 expected.push_back('a'); 1953 expected.push_back('a');
1938 EXPECT_TRUE(expected == repl_str); 1954 EXPECT_TRUE(expected == repl_str);
1939 } 1955 }
OLDNEW
« src/url_canon_ip.cc ('K') | « src/url_canon_ip.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698