aboutsummaryrefslogtreecommitdiff
path: root/HutchTests/ReadmeViewTests.swift
blob: 9c3c0197f266e11085733295f4378df02c9456ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Foundation
import Testing
@testable import Hutch

struct ReadmeViewTests {

    @Test
    func sanitizedReadmeLinkURLStringRejectsUnexpectedSchemes() {
        #expect(sanitizedReadmeLinkURLString("javascript:alert(1)") == nil)
        #expect(sanitizedReadmeLinkURLString("file:///tmp/readme") == nil)
        #expect(sanitizedReadmeLinkURLString("data:text/html;base64,SGVsbG8=") == nil)
    }

    @Test
    func processInlineDropsUnsafeMarkdownLinks() {
        let rendered = processInline("[click me](javascript:alert)")

        #expect(rendered == "click me")
        #expect(!rendered.contains("href="))
        #expect(!rendered.contains("javascript:"))
    }

    @Test
    func sanitizedReadmeLinkURLStringAllowsExpectedDestinations() {
        #expect(sanitizedReadmeLinkURLString("https://example.com/docs?q=1") == "https://example.com/docs?q=1")
        #expect(sanitizedReadmeLinkURLString("mailto:[email protected]") == "mailto:[email protected]")
        #expect(sanitizedReadmeLinkURLString("#readme") == "#readme")
    }
}