| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class _HttpUtils { | 5 class _HttpUtils { |
| 6 static String decodeUrlEncodedString(String urlEncoded) { | 6 static String decodeUrlEncodedString(String urlEncoded) { |
| 7 // First check the string for any encoding. | 7 // First check the string for any encoding. |
| 8 int index = 0; | 8 int index = 0; |
| 9 bool encoded = false; | 9 bool encoded = false; |
| 10 while (!encoded && index < urlEncoded.length) { | 10 while (!encoded && index < urlEncoded.length) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 void error() { | 255 void error() { |
| 256 throw new HttpException("Invalid cookie date $date"); | 256 throw new HttpException("Invalid cookie date $date"); |
| 257 } | 257 } |
| 258 | 258 |
| 259 bool isEnd() { | 259 bool isEnd() { |
| 260 return position == date.length; | 260 return position == date.length; |
| 261 } | 261 } |
| 262 | 262 |
| 263 bool isDelimiter(String s) { | 263 bool isDelimiter(String s) { |
| 264 int char = s.charCodeAt(0); | 264 int char = s.charCodeAt(0); |
| 265 if (char === 0x09) return true; | 265 if (char == 0x09) return true; |
| 266 if (char >= 0x20 && char <= 0x2F) return true; | 266 if (char >= 0x20 && char <= 0x2F) return true; |
| 267 if (char >= 0x3B && char <= 0x40) return true; | 267 if (char >= 0x3B && char <= 0x40) return true; |
| 268 if (char >= 0x5B && char <= 0x60) return true; | 268 if (char >= 0x5B && char <= 0x60) return true; |
| 269 if (char >= 0x7B && char <= 0x7E) return true; | 269 if (char >= 0x7B && char <= 0x7E) return true; |
| 270 return false; | 270 return false; |
| 271 } | 271 } |
| 272 | 272 |
| 273 bool isNonDelimiter(String s) { | 273 bool isNonDelimiter(String s) { |
| 274 int char = s.charCodeAt(0); | 274 int char = s.charCodeAt(0); |
| 275 if (char >= 0x00 && char <= 0x08) return true; | 275 if (char >= 0x00 && char <= 0x08) return true; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 while (!isEnd() && isDelimiter(date[position])) position++; | 308 while (!isEnd() && isDelimiter(date[position])) position++; |
| 309 } | 309 } |
| 310 | 310 |
| 311 String timeStr; | 311 String timeStr; |
| 312 String dayOfMonthStr; | 312 String dayOfMonthStr; |
| 313 String monthStr; | 313 String monthStr; |
| 314 String yearStr; | 314 String yearStr; |
| 315 | 315 |
| 316 for (var token in tokens) { | 316 for (var token in tokens) { |
| 317 if (token.length < 1) continue; | 317 if (token.length < 1) continue; |
| 318 if (timeStr === null && token.length >= 5 && isDigit(token[0]) && | 318 if (timeStr == null && token.length >= 5 && isDigit(token[0]) && |
| 319 (token[1] == ":" || (isDigit(token[1]) && token[2] == ":"))) { | 319 (token[1] == ":" || (isDigit(token[1]) && token[2] == ":"))) { |
| 320 timeStr = token; | 320 timeStr = token; |
| 321 } else if (dayOfMonthStr === null && isDigit(token[0])) { | 321 } else if (dayOfMonthStr == null && isDigit(token[0])) { |
| 322 dayOfMonthStr = token; | 322 dayOfMonthStr = token; |
| 323 } else if (monthStr === null && getMonth(token) >= 0) { | 323 } else if (monthStr == null && getMonth(token) >= 0) { |
| 324 monthStr = token; | 324 monthStr = token; |
| 325 } else if (yearStr === null && token.length >= 2 && | 325 } else if (yearStr == null && token.length >= 2 && |
| 326 isDigit(token[0]) && isDigit(token[1])) { | 326 isDigit(token[0]) && isDigit(token[1])) { |
| 327 yearStr = token; | 327 yearStr = token; |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 | 330 |
| 331 if (timeStr === null || dayOfMonthStr === null || | 331 if (timeStr == null || dayOfMonthStr == null || |
| 332 monthStr === null || yearStr === null) { | 332 monthStr == null || yearStr == null) { |
| 333 error(); | 333 error(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 int year = toInt(yearStr); | 336 int year = toInt(yearStr); |
| 337 if (year >= 70 && year <= 99) year += 1900; | 337 if (year >= 70 && year <= 99) year += 1900; |
| 338 else if (year >= 0 && year <= 69) year += 2000; | 338 else if (year >= 0 && year <= 69) year += 2000; |
| 339 if (year < 1601) error(); | 339 if (year < 1601) error(); |
| 340 | 340 |
| 341 int dayOfMonth = toInt(dayOfMonthStr); | 341 int dayOfMonth = toInt(dayOfMonthStr); |
| 342 if (dayOfMonth < 1 || dayOfMonth > 31) error(); | 342 if (dayOfMonth < 1 || dayOfMonth > 31) error(); |
| 343 | 343 |
| 344 int month = getMonth(monthStr) + 1; | 344 int month = getMonth(monthStr) + 1; |
| 345 | 345 |
| 346 var timeList = timeStr.split(":"); | 346 var timeList = timeStr.split(":"); |
| 347 if (timeList.length !== 3) error(); | 347 if (timeList.length != 3) error(); |
| 348 int hour = toInt(timeList[0]); | 348 int hour = toInt(timeList[0]); |
| 349 int minute = toInt(timeList[1]); | 349 int minute = toInt(timeList[1]); |
| 350 int second = toInt(timeList[2]); | 350 int second = toInt(timeList[2]); |
| 351 if (hour > 23) error(); | 351 if (hour > 23) error(); |
| 352 if (minute > 59) error(); | 352 if (minute > 59) error(); |
| 353 if (second > 59) error(); | 353 if (second > 59) error(); |
| 354 | 354 |
| 355 return new Date.utc(year, month, dayOfMonth, hour, minute, second, 0); | 355 return new Date.utc(year, month, dayOfMonth, hour, minute, second, 0); |
| 356 } | 356 } |
| 357 } | 357 } |
| OLD | NEW |