mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 16:26:04 +00:00
54 lines
2.0 KiB
Swift
54 lines
2.0 KiB
Swift
//
|
|
// URLPreparedForOpeningTests.swift
|
|
// RSWebTests
|
|
//
|
|
// Created by Brent Simmons on 9/1/26.
|
|
//
|
|
|
|
import Foundation
|
|
import Testing
|
|
import RSWeb
|
|
|
|
struct URLPreparedForOpeningTests {
|
|
|
|
@Test func allowsWebAndMailSchemes() throws {
|
|
#expect(try url("http://example.com/").preparedForOpeningInBrowser() != nil)
|
|
#expect(try url("https://example.com/").preparedForOpeningInBrowser() != nil)
|
|
#expect(try url("mailto:me@example.com").preparedForOpeningInBrowser() != nil)
|
|
}
|
|
|
|
#if os(macOS)
|
|
@Test func allowsMagnetScheme() throws {
|
|
#expect(try url("magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a&dn=example").preparedForOpeningInBrowser() != nil)
|
|
#expect(try url("Magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a").preparedForOpeningInBrowser() != nil)
|
|
}
|
|
#else
|
|
@Test func blocksMagnetScheme() throws {
|
|
#expect(try url("magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a&dn=example").preparedForOpeningInBrowser() == nil)
|
|
}
|
|
#endif
|
|
|
|
@Test func blocksOtherSchemes() throws {
|
|
#expect(try url("smb://server/share").preparedForOpeningInBrowser() == nil)
|
|
#expect(try url("file:///etc/passwd").preparedForOpeningInBrowser() == nil)
|
|
#expect(try url("ftp://example.com/x").preparedForOpeningInBrowser() == nil)
|
|
#expect(try url("javascript:alert(1)").preparedForOpeningInBrowser() == nil)
|
|
#expect(try url("data:text/html,x").preparedForOpeningInBrowser() == nil)
|
|
#expect(try url("tel:+15555555555").preparedForOpeningInBrowser() == nil)
|
|
}
|
|
|
|
@Test func schemeMatchIsCaseInsensitive() throws {
|
|
#expect(try url("HTTPS://example.com/").preparedForOpeningInBrowser() != nil)
|
|
#expect(try url("MailTo:me@example.com").preparedForOpeningInBrowser() != nil)
|
|
}
|
|
|
|
@Test func allowedURLPassesThroughUnchanged() throws {
|
|
let prepared = try #require(url("http://example.com/path?q=1").preparedForOpeningInBrowser())
|
|
#expect(prepared.absoluteString == "http://example.com/path?q=1")
|
|
}
|
|
|
|
private func url(_ string: String) throws -> URL {
|
|
try #require(URL(string: string))
|
|
}
|
|
}
|