OLD | NEW |
---|---|
1 // Copyright 2009, Google Inc. | 1 // Copyright 2009, 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 return 8; | 51 return 8; |
52 default: | 52 default: |
53 return 0; | 53 return 0; |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 template<typename CHAR, typename UCHAR> | 57 template<typename CHAR, typename UCHAR> |
58 bool DoFindIPv4Components(const CHAR* spec, | 58 bool DoFindIPv4Components(const CHAR* spec, |
59 const url_parse::Component& host, | 59 const url_parse::Component& host, |
60 url_parse::Component components[4]) { | 60 url_parse::Component components[4]) { |
61 if (!host.is_nonempty()) | |
62 return false; | |
63 | |
61 int cur_component = 0; // Index of the component we're working on. | 64 int cur_component = 0; // Index of the component we're working on. |
62 int cur_component_begin = host.begin; // Start of the current component. | 65 int cur_component_begin = host.begin; // Start of the current component. |
63 int end = host.end(); | 66 int end = host.end(); |
64 for (int i = host.begin; /* nothing */; i++) { | 67 for (int i = host.begin; /* nothing */; i++) { |
65 if (i == end || spec[i] == '.') { | 68 if (i >= end || spec[i] == '.') { |
66 // Found the end of the current component. | 69 // Found the end of the current component. |
67 int component_len = i - cur_component_begin; | 70 int component_len = i - cur_component_begin; |
68 components[cur_component] = | 71 components[cur_component] = |
69 url_parse::Component(cur_component_begin, component_len); | 72 url_parse::Component(cur_component_begin, component_len); |
70 | 73 |
71 // The next component starts after the dot. | 74 // The next component starts after the dot. |
72 cur_component_begin = i + 1; | 75 cur_component_begin = i + 1; |
73 cur_component++; | 76 cur_component++; |
74 | 77 |
75 // Don't allow empty components (two dots in a row), except we may | 78 // Don't allow empty components (two dots in a row), except we may |
76 // allow an empty component at the end (this would indicate that the | 79 // allow an empty component at the end (this would indicate that the |
77 // input ends in a dot). We also want to error if the component is | 80 // input ends in a dot). We also want to error if the component is |
78 // empty and it's the only component (cur_component == 1). | 81 // empty and it's the only component (cur_component == 1). |
79 if (component_len == 0 && (i != end || cur_component == 1)) | 82 if (component_len == 0 && (i != end || cur_component == 1)) |
Peter Kasting
2010/05/11 18:34:33
You should change "i != end" to "i < end" here.
| |
80 return false; | 83 return false; |
81 | 84 |
82 if (i == end) | 85 if (i >= end) |
83 break; // End of the input. | 86 break; // End of the input. |
84 | 87 |
85 if (cur_component == 4) { | 88 if (cur_component == 4) { |
86 // Anything else after the 4th component is an error unless it is a | 89 // Anything else after the 4th component is an error unless it is a |
87 // dot that would otherwise be treated as the end of input. | 90 // dot that would otherwise be treated as the end of input. |
88 if (spec[i] == '.' && i + 1 == end) | 91 if (spec[i] == '.' && i + 1 == end) |
89 break; | 92 break; |
90 return false; | 93 return false; |
91 } | 94 } |
92 } else if (static_cast<UCHAR>(spec[i]) >= 0x80 || | 95 } else if (static_cast<UCHAR>(spec[i]) >= 0x80 || |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 } | 728 } |
726 | 729 |
727 bool IPv6AddressToNumber(const char16* spec, | 730 bool IPv6AddressToNumber(const char16* spec, |
728 const url_parse::Component& host, | 731 const url_parse::Component& host, |
729 unsigned char address[16]) { | 732 unsigned char address[16]) { |
730 return DoIPv6AddressToNumber<char16, char16>(spec, host, address); | 733 return DoIPv6AddressToNumber<char16, char16>(spec, host, address); |
731 } | 734 } |
732 | 735 |
733 | 736 |
734 } // namespace url_canon | 737 } // namespace url_canon |
OLD | NEW |