@@ -435,41 +435,6 @@ internal struct RFC3986Parser {
435
435
return validate ( string: password, component: . password, percentEncodingAllowed: percentEncodingAllowed)
436
436
}
437
437
438
- private static func isIPvFuture( _ innerHost: some StringProtocol ) -> Bool {
439
- // precondition: IP-literal == "[" innerHost [ "%25" zoneID ] "]"
440
- var iter = innerHost. utf8. makeIterator ( )
441
- guard iter. next ( ) == UInt8 ( ascii: " v " ) else { return false }
442
- guard let second = iter. next ( ) , second. isValidHexDigit else { return false }
443
- while let next = iter. next ( ) {
444
- if next. isValidHexDigit { continue }
445
- if next == . _dot { return true }
446
- return false
447
- }
448
- return false
449
- }
450
-
451
- /// Only checks that the characters are allowed in an IPv6 address.
452
- /// Does not validate the format of the IPv6 address.
453
- private static func validateIPv6Address( _ address: some StringProtocol ) -> Bool {
454
- let isValid = address. utf8. withContiguousStorageIfAvailable {
455
- $0. allSatisfy { $0. isValidHexDigit || $0 == UInt8 ( ascii: " : " ) || $0 == UInt8 ( ascii: " . " ) }
456
- }
457
- if let isValid {
458
- return isValid
459
- }
460
- #if FOUNDATION_FRAMEWORK
461
- if let fastCharacters = address. _ns. _fastCharacterContents ( ) {
462
- let charsBuffer = UnsafeBufferPointer ( start: fastCharacters, count: address. _ns. length)
463
- return charsBuffer. allSatisfy {
464
- guard $0 < 128 else { return false }
465
- let v = UInt8 ( $0)
466
- return v. isValidHexDigit || v == UInt8 ( ascii: " : " ) || v == UInt8 ( ascii: " . " )
467
- }
468
- }
469
- #endif
470
- return address. utf8. allSatisfy { $0. isValidHexDigit || $0 == UInt8 ( ascii: " : " ) || $0 == UInt8 ( ascii: " . " ) }
471
- }
472
-
473
438
/// Validates an IP-literal host string that has leading and trailing brackets.
474
439
/// If the host string contains a zone ID delimiter "%", this must be percent encoded to "%25" to be valid.
475
440
/// The zone ID may contain any `reg_name` characters, including percent-encoding.
@@ -483,11 +448,7 @@ internal struct RFC3986Parser {
483
448
484
449
guard let percentIndex = utf8. firstIndex ( of: UInt8 ( ascii: " % " ) ) else {
485
450
// There is no zoneID, so the whole innerHost must be the IP-literal address.
486
- if isIPvFuture ( innerHost) {
487
- return validate ( string: innerHost, component: . hostIPvFuture, percentEncodingAllowed: false )
488
- } else {
489
- return validateIPv6Address ( innerHost)
490
- }
451
+ return validate ( string: innerHost, component: . hostIPvFuture, percentEncodingAllowed: false )
491
452
}
492
453
493
454
// The first "%" in an IP-literal must be the zone ID delimiter.
@@ -503,11 +464,7 @@ internal struct RFC3986Parser {
503
464
return false
504
465
}
505
466
506
- if isIPvFuture ( innerHost) {
507
- return validate ( string: innerHost [ ..< percentIndex] , component: . hostIPvFuture, percentEncodingAllowed: false ) && validate ( string: innerHost [ innerHost. index ( after: twoAfterIndex) ... ] , component: . hostZoneID)
508
- } else {
509
- return validateIPv6Address ( innerHost [ ..< percentIndex] ) && validate ( string: innerHost [ innerHost. index ( after: twoAfterIndex) ... ] , component: . hostZoneID)
510
- }
467
+ return validate ( string: innerHost [ ..< percentIndex] , component: . hostIPvFuture, percentEncodingAllowed: false ) && validate ( string: innerHost [ innerHost. index ( after: twoAfterIndex) ... ] , component: . hostZoneID)
511
468
}
512
469
513
470
private static func validate( host: some StringProtocol , knownIPLiteral: Bool = false ) -> Bool {
0 commit comments