mirror of
https://github.com/yattee/yattee.git
synced 2024-12-24 06:23:42 +00:00
Fix channels URL parsing
This commit is contained in:
parent
accd78be92
commit
ce1d832993
@ -55,6 +55,7 @@ final class URLParserTests: XCTestCase {
|
|||||||
let parser = URLParser(url: URL(string: url)!)
|
let parser = URLParser(url: URL(string: url)!)
|
||||||
XCTAssertEqual(parser.destination, .channel)
|
XCTAssertEqual(parser.destination, .channel)
|
||||||
XCTAssertEqual(parser.channelName, name)
|
XCTAssertEqual(parser.channelName, name)
|
||||||
|
XCTAssertNil(parser.channelID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ final class URLParserTests: XCTestCase {
|
|||||||
let parser = URLParser(url: URL(string: url)!)
|
let parser = URLParser(url: URL(string: url)!)
|
||||||
XCTAssertEqual(parser.destination, .channel)
|
XCTAssertEqual(parser.destination, .channel)
|
||||||
XCTAssertEqual(parser.channelID, id)
|
XCTAssertEqual(parser.channelID, id)
|
||||||
|
XCTAssertNil(parser.channelName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,13 +75,12 @@ struct URLParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var channelName: String? {
|
var channelName: String? {
|
||||||
guard destination == .channel else { return nil }
|
guard hasAnyOfPrefixes(path, ["c/", "/c/"]) else { return nil }
|
||||||
|
|
||||||
return removePrefixes(path, Self.prefixes[.channel]!.map { [$0, "/"].joined() })
|
return removePrefixes(path, Self.prefixes[.channel]!.map { [$0, "/"].joined() })
|
||||||
}
|
}
|
||||||
|
|
||||||
var channelID: String? {
|
var channelID: String? {
|
||||||
guard destination == .channel else { return nil }
|
guard hasAnyOfPrefixes(path, ["channel/", "/channel/"]) else { return nil }
|
||||||
|
|
||||||
return removePrefixes(path, Self.prefixes[.channel]!.map { [$0, "/"].joined() })
|
return removePrefixes(path, Self.prefixes[.channel]!.map { [$0, "/"].joined() })
|
||||||
}
|
}
|
||||||
@ -95,7 +94,7 @@ struct URLParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func hasAnyOfPrefixes(_ value: String, _ prefixes: [String]) -> Bool {
|
private func hasAnyOfPrefixes(_ value: String, _ prefixes: [String]) -> Bool {
|
||||||
return prefixes.contains { value.hasPrefix($0) }
|
prefixes.contains { value.hasPrefix($0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private func removePrefixes(_ value: String, _ prefixes: [String]) -> String {
|
private func removePrefixes(_ value: String, _ prefixes: [String]) -> String {
|
||||||
|
Loading…
Reference in New Issue
Block a user