Skip to content

Commit

Permalink
update netaddr test
Browse files Browse the repository at this point in the history
  • Loading branch information
MacOMNI committed Oct 23, 2024
1 parent f190901 commit 83afeea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Boka/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Networking/Sources/MsQuicSwift/NetAddr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private func parseQuicAddr(_ addr: QUIC_ADDR) -> (String, UInt16, Bool)? {
private func parseIpv4Addr(_ address: String) -> (String, UInt16)? {
let ipv4Pattern =
#"((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"#
let ipv4WithPortPattern = #"(\#(ipv4Pattern)):(\d{1,5})"#
let ipv4WithPortPattern = #"(\#(ipv4Pattern)):(\d{1,5})(?=\s*$|\s+)"#

let regex = try? NSRegularExpression(pattern: ipv4WithPortPattern, options: [])
let range = NSRange(location: 0, length: address.utf16.count)
Expand Down Expand Up @@ -142,7 +142,7 @@ private func parseIpv6Addr(_ address: String) -> (String, UInt16)? {
"|(?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::",
")",
].reduce("", +)
let ipv6WithPortPattern = #"\[(\#(ipv6Pattern))\]:(\d{1,5})"#
let ipv6WithPortPattern = #"\[(\#(ipv6Pattern))\]:(\d{1,5})(?=\s*$|\s+)"#

let regex = try? NSRegularExpression(pattern: ipv6WithPortPattern, options: [])
let range = NSRange(location: 0, length: address.utf16.count)
Expand Down
12 changes: 9 additions & 3 deletions Networking/Tests/MsQuicSwiftTests/NetAddrTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ struct NetAddrTests {

@Test
func parseInvalidFormat() async throws {
let address = "abcd:::"
let netAddr = NetAddr(address: address)
#expect(netAddr == nil)
let address1 = "abcd:::"
let netAddr1 = NetAddr(address: address1)
#expect(netAddr1 == nil)
let address2 = "127.0.0.1:12,awef"
let netAddr2 = NetAddr(address: address2)
#expect(netAddr2 == nil)
let address3 = "[2001:db8:85a3::8a2e:370:7334]:8080,8081,8082"
let netAddr3 = NetAddr(address: address3)
#expect(netAddr3 == nil)
}

@Test
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 83afeea

Please sign in to comment.