Skip to content

Commit 74fbe3f

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 e824c42 commit 74fbe3f

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

Sources/SwiftDocC/Infrastructure/NodeURLGenerator.swift

Lines changed: 7 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ Root
891891
XCTAssertEqual(navigatorIndex.path(for: 4), "/tutorials/testoverview")
892892
XCTAssertEqual(navigatorIndex.path(for: 9), "/documentation/fillintroduced/maccatalystonlydeprecated()")
893893
XCTAssertEqual(navigatorIndex.path(for: 10), "/documentation/fillintroduced/maccatalystonlyintroduced()")
894-
XCTAssertEqual(navigatorIndex.path(for: 21), "/documentation/mykit/globalfunction(_:considering:)")
894+
XCTAssertEqual(navigatorIndex.path(for: 21), "/documentation/mykit/globalfunction(__considering_)")
895895
XCTAssertEqual(navigatorIndex.path(for: 23), "/documentation/sidekit/uncuratedclass/angle")
896896

897897
assertUniqueIDs(node: navigatorIndex.navigatorTree.root)

Tests/SwiftDocCTests/Indexing/RenderIndexTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ final class RenderIndexTests: XCTestCase {
9999
"type": "groupMarker"
100100
},
101101
{
102-
"path": "/documentation/mixedlanguageframework/bar/mystringfunction(_:)",
102+
"path": "/documentation/mixedlanguageframework/bar/mystringfunction(__)",
103103
"title": "myStringFunction:error: (navigator title)",
104104
"type": "method",
105105
"children": [
@@ -327,7 +327,7 @@ final class RenderIndexTests: XCTestCase {
327327
},
328328
{
329329
"title": "class func myStringFunction(String) throws -> String",
330-
"path": "/documentation/mixedlanguageframework/bar/mystringfunction(_:)",
330+
"path": "/documentation/mixedlanguageframework/bar/mystringfunction(__)",
331331
"type": "method"
332332
}
333333
]
@@ -488,7 +488,7 @@ final class RenderIndexTests: XCTestCase {
488488
"type": "groupMarker"
489489
},
490490
{
491-
"path": "\/documentation\/mixedlanguageframework\/foo-swift.struct\/init(rawvalue:)",
491+
"path": "\/documentation\/mixedlanguageframework\/foo-swift.struct\/init(rawvalue_)",
492492
"title": "init(rawValue: UInt)",
493493
"type": "init"
494494
},

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class ExternalLinkableTests: XCTestCase {
287287
let summary = node.externallyLinkableElementSummaries(context: context, renderNode: renderNode)[0]
288288

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

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

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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class ConvertActionTests: XCTestCase {
330330
"/output/data/documentation/mykit/myclass/init()-3743d.json",
331331
"/output/data/documentation/mykit/myclass/myfunction().json",
332332
"/output/data/documentation/mykit/myprotocol.json",
333-
"/output/data/documentation/mykit/globalfunction(_:considering:).json",
333+
"/output/data/documentation/mykit/globalfunction(__considering_).json",
334334
].sorted())
335335

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

0 commit comments

Comments
 (0)