@@ -247,43 +247,37 @@ inline bool ipv6_parse(const CharT* first, const CharT* last, uint16_t(&pieces)[
247247 // TODO-ERR: syntax violation
248248 return false ;
249249 }
250- int dots_seen = 0 ;
250+ int numbers_seen = 0 ;
251251 while (pointer < last) {
252- CharT c = *pointer;
253- if (!IsAsciiDigit (c)) {
252+ if (numbers_seen > 0 ) {
253+ if (*pointer == ' .' && numbers_seen < 4 ) {
254+ ++pointer;
255+ } else {
256+ // TODO-ERR: syntax violation
257+ return false ;
258+ }
259+ }
260+ if (pointer == last || !IsAsciiDigit (*pointer)) {
254261 // TODO-ERR: syntax violation
255262 return false ;
256263 }
257264 // While c is an ASCII digit, run these subsubsteps
258- unsigned value = c - ' 0' ; pointer++;
259- while (pointer != last) {
260- c = *pointer;
261- if (IsAsciiDigit (c)) {
262- if (value == 0 ) // leading zero
263- return false ; // TODO-ERR: syntax violation
264- value = value * 10 + (c - ' 0' ); pointer++;
265- if (value > 255 )
266- return false ; // TODO-ERR: syntax violation
267- } else {
268- // 10.4. If dots seen is less than 3 and c is not a "."
269- // and URL standart BUG workaround (10.7.) ==> 10.8 check
270- if (dots_seen == 3 || c != ' .' ) {
271- // TODO-ERR: syntax violation
272- return false ;
273- }
274- pointer++; // skip '.' (Fix of 10.7.)
275- break ;
276- }
265+ unsigned value = *(pointer++) - ' 0' ;
266+ while (pointer != last && IsAsciiDigit (*pointer)) {
267+ if (value == 0 ) // leading zero
268+ return false ; // TODO-ERR: syntax violation
269+ value = value * 10 + (*pointer - ' 0' );
270+ pointer++;
271+ if (value > 255 )
272+ return false ; // TODO-ERR: syntax violation
277273 }
278- // *(pointer-1) == '.' || EOF
279274 pieces[piece_pointer] = pieces[piece_pointer] * 0x100 + value;
280- if (dots_seen & 1 ) // is 1 or 3
275+ numbers_seen++;
276+ if (!(numbers_seen & 1 )) // 2 or 4
281277 piece_pointer++;
282- // 9. Increase dots seen by one
283- dots_seen++;
284278 }
285- // 10.4. tikrinimas kai EOF ir dots_seen padidintas vienetu
286- if (dots_seen < 4 ) {
279+ // If c is the EOF code point and numbersSeen is not 4
280+ if (numbers_seen != 4 ) {
287281 // TODO-ERR: syntax violation
288282 return false ;
289283 }
0 commit comments