Skip to content

Commit ca120e1

Browse files
authored
Support documentation extensions on Linux for symbols with spaces in their name (#782)
1 parent 159f74f commit ca120e1

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,9 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
12611261
diagnosticEngine.emit(Problem(diagnostic: diagnostic))
12621262
continue
12631263
}
1264-
guard let url = ValidatedURL(parsingExact: destination) else {
1264+
guard let url = ValidatedURL(parsingAuthoredLink: destination) else {
12651265
let diagnostic = Diagnostic(source: documentationExtension.source, severity: .warning, range: link.range, identifier: "org.swift.docc.invalidLinkDestination", summary: """
1266-
\(destination.singleQuoted) is
1266+
\(destination.singleQuoted) is not a valid RFC 3986 URL.
12671267
""", explanation: nil, notes: [])
12681268
diagnosticEngine.emit(Problem(diagnostic: diagnostic))
12691269
continue

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,47 @@ let expected = """
20642064
XCTAssertEqual(unmatchedSidecarDiagnostic.severity, .warning)
20652065
}
20662066

2067+
func testExtendingSymbolWithSpaceInName() throws {
2068+
let exampleDocumentation = Folder(name: "unit-test.docc", content: [
2069+
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(
2070+
moduleName: "ModuleName",
2071+
symbols: [
2072+
SymbolGraph.Symbol(
2073+
identifier: .init(precise: "symbol-id", interfaceLanguage: "swift"),
2074+
names: .init(title: "Symbol Name", navigator: nil, subHeading: nil, prose: nil),
2075+
pathComponents: ["Symbol Name"],
2076+
docComment: nil,
2077+
accessLevel: .public,
2078+
kind: .init(parsedIdentifier: .class, displayName: "Kind Display Name"),
2079+
mixins: [:]
2080+
)
2081+
]
2082+
)),
2083+
2084+
TextFile(name: "Extension.md", utf8Content: """
2085+
# ``Symbol Name``
2086+
2087+
Extend a symbol with a space in its name.
2088+
"""),
2089+
2090+
TextFile(name: "Article.md", utf8Content: """
2091+
# Article
2092+
2093+
Link in content to a symbol with a space in its name: ``Symbol Name``.
2094+
"""),
2095+
])
2096+
2097+
let tempURL = try createTempFolder(content: [exampleDocumentation])
2098+
let (_, bundle, context) = try loadBundle(from: tempURL)
2099+
2100+
XCTAssert(context.problems.isEmpty, "Unexpected problems: \(context.problems.map(\.diagnostic.summary).joined(separator: "\n"))")
2101+
2102+
let reference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/ModuleName/Symbol_Name", sourceLanguage: .swift)
2103+
let node = try context.entity(with: reference)
2104+
2105+
XCTAssertEqual((node.semantic as? Symbol)?.abstract?.plainText, "Extend a symbol with a space in its name.")
2106+
}
2107+
20672108
func testDeprecationSummaryWithLocalLink() throws {
20682109
let exampleDocumentation = Folder(name: "unit-test.docc", content: [
20692110
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(

0 commit comments

Comments
 (0)