Skip to content

Commit f274579

Browse files
committed
SwiftDocC: use "portable" paths for file names
Windows restricts a CharacterSet from use in the file name. Replace that set with `_`. This requires an associated change in the DocC renderer to perform the substitution when converting the URL to a file path.
1 parent 5ad35a3 commit f274579

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

Sources/SwiftDocC/Infrastructure/NodeURLGenerator.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ public struct NodeURLGenerator {
194194
isURLModified = true
195195
name = "'\(name)"
196196
}
197-
197+
198+
let components = name.components(separatedBy: ["<", ">", ":", "\"", "/", "\\", "|", "?", "*"])
199+
if components.count > 1 {
200+
isURLModified = true
201+
name = components.joined(separator: "_")
202+
}
203+
198204
// Shorten path components that are too long.
199205
// Take the first 240 chars and append a checksum on the *complete* string.
200206
if name.count >= pathComponentLengthLimit {

Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ Root
706706
XCTAssertEqual(navigatorIndex.path(for: 4), "/tutorials/testoverview")
707707
XCTAssertEqual(navigatorIndex.path(for: 9), "/documentation/fillintroduced/maccatalystonlydeprecated()")
708708
XCTAssertEqual(navigatorIndex.path(for: 10), "/documentation/fillintroduced/maccatalystonlyintroduced()")
709-
XCTAssertEqual(navigatorIndex.path(for: 21), "/documentation/mykit/globalfunction(_:considering:)")
709+
XCTAssertEqual(navigatorIndex.path(for: 21), "/documentation/mykit/globalfunction(__considering_)")
710710
XCTAssertEqual(navigatorIndex.path(for: 23), "/documentation/sidekit/uncuratedclass/angle")
711711

712712
assertUniqueIDs(node: navigatorIndex.navigatorTree.root)

Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ final class RenderIndexTests: XCTestCase {
9696
"type": "groupMarker"
9797
},
9898
{
99-
"path": "/documentation/mixedlanguageframework/bar/mystringfunction(_:)",
99+
"path": "/documentation/mixedlanguageframework/bar/mystringfunction(__)",
100100
"title": "myStringFunction:error: (navigator title)",
101101
"type": "method",
102102
"children": [
@@ -324,7 +324,7 @@ final class RenderIndexTests: XCTestCase {
324324
},
325325
{
326326
"title": "class func myStringFunction(String) throws -> String",
327-
"path": "/documentation/mixedlanguageframework/bar/mystringfunction(_:)",
327+
"path": "/documentation/mixedlanguageframework/bar/mystringfunction(__)",
328328
"type": "method"
329329
}
330330
]
@@ -485,7 +485,7 @@ final class RenderIndexTests: XCTestCase {
485485
"type": "groupMarker"
486486
},
487487
{
488-
"path": "\/documentation\/mixedlanguageframework\/foo-swift.struct\/init(rawvalue:)",
488+
"path": "\/documentation\/mixedlanguageframework\/foo-swift.struct\/init(rawvalue_)",
489489
"title": "init(rawValue: UInt)",
490490
"type": "init"
491491
},

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class DocumentationContextTests: XCTestCase {
474474
Folder(name: "Resources", content: [
475475
// This whitespace and punctuation in this *file name* will be replaced by dashes in its identifier.
476476
// No content in this file result in identifiers.
477-
TextFile(name: "Technology file: with - whitespace, and_punctuation.tutorial", utf8Content: """
477+
TextFile(name: "Technology file_ with - whitespace, and_punctuation.tutorial", utf8Content: """
478478
@Tutorials(name: "Technology Name") {
479479
@Intro(title: "Intro Title") {
480480
@Video(source: introvideo.mp4, poster: introposter.png)
@@ -510,10 +510,10 @@ class DocumentationContextTests: XCTestCase {
510510
let identifierPaths = context.knownIdentifiers.map { $0.path }.sorted(by: { lhs, rhs in lhs.count < rhs.count })
511511
XCTAssertEqual(identifierPaths, [
512512
// From the two file names
513-
"/tutorials/Technology-file:-with---whitespace,-and_punctuation",
513+
"/tutorials/Technology-file_-with---whitespace,-and_punctuation",
514514
// From the volume's title and the chapter's names, appended to their technology's identifier
515-
"/tutorials/Technology-file:-with---whitespace,-and_punctuation/Volume_Section-Title:-with---various!-whitespace,-and/punctuation",
516-
"/tutorials/Technology-file:-with---whitespace,-and_punctuation/Volume_Section-Title:-with---various!-whitespace,-and/punctuation/Chapter_Title:-with---various!-whitespace,-and/punctuation"
515+
"/tutorials/Technology-file_-with---whitespace,-and_punctuation/Volume_Section-Title:-with---various!-whitespace,-and/punctuation",
516+
"/tutorials/Technology-file_-with---whitespace,-and_punctuation/Volume_Section-Title:-with---various!-whitespace,-and/punctuation/Chapter_Title:-with---various!-whitespace,-and/punctuation"
517517
])
518518
}
519519

Tests/SwiftDocCTests/LinkTargets/LinkDestinationSummaryTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class ExternalLinkableTests: XCTestCase {
286286
let summary = node.externallyLinkableElementSummaries(context: context, renderNode: renderNode)[0]
287287

288288
XCTAssertEqual(summary.title, "globalFunction(_:considering:)")
289-
XCTAssertEqual(summary.relativePresentationURL.absoluteString, "/documentation/mykit/globalfunction(_:considering:)")
289+
XCTAssertEqual(summary.relativePresentationURL.absoluteString, "/documentation/mykit/globalfunction(__considering_)")
290290
XCTAssertEqual(summary.referenceURL.absoluteString, "doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)")
291291
XCTAssertEqual(summary.language, .swift)
292292
XCTAssertEqual(summary.kind, .function)
@@ -507,7 +507,7 @@ class ExternalLinkableTests: XCTestCase {
507507
let summary = node.externallyLinkableElementSummaries(context: context, renderNode: renderNode)[0]
508508

509509
XCTAssertEqual(summary.title, "myStringFunction(_:)")
510-
XCTAssertEqual(summary.relativePresentationURL.absoluteString, "/documentation/mixedlanguageframework/bar/mystringfunction(_:)")
510+
XCTAssertEqual(summary.relativePresentationURL.absoluteString, "/documentation/mixedlanguageframework/bar/mystringfunction(__)")
511511
XCTAssertEqual(summary.referenceURL.absoluteString, "doc://org.swift.MixedLanguageFramework/documentation/MixedLanguageFramework/Bar/myStringFunction(_:)")
512512
XCTAssertEqual(summary.language, .swift)
513513
XCTAssertEqual(summary.kind, .typeMethod)

Tests/SwiftDocCTests/Test Resources/TestBundle-RenderIndex.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@
614614
"type" : "groupMarker"
615615
},
616616
{
617-
"path" : "\/documentation\/mykit\/globalfunction(_:considering:)",
617+
"path" : "\/documentation\/mykit\/globalfunction(__considering_)",
618618
"title" : "func globalFunction(Data, considering: Int)",
619619
"type" : "func"
620620
},
@@ -638,7 +638,7 @@
638638
"type" : "groupMarker"
639639
},
640640
{
641-
"path" : "\/documentation\/sidekit\/sideclass\/value(_:)",
641+
"path" : "\/documentation\/sidekit\/sideclass\/value(__)",
642642
"title" : "case Value(Int)",
643643
"type" : "case"
644644
},

Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class ConvertActionTests: XCTestCase {
324324
"/output/data/documentation/mykit/myclass/init()-3743d.json",
325325
"/output/data/documentation/mykit/myclass/myfunction().json",
326326
"/output/data/documentation/mykit/myprotocol.json",
327-
"/output/data/documentation/mykit/globalfunction(_:considering:).json",
327+
"/output/data/documentation/mykit/globalfunction(__considering_).json",
328328
].sorted())
329329

330330
let myKitNodeData = try XCTUnwrap(outputData["/output/data/documentation/mykit.json"])

0 commit comments

Comments
 (0)