Skip to content

Commit 9f46326

Browse files
committed
tolerate codelinks with trailing slashes
1 parent 312ad0f commit 9f46326

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

Sources/CodelinkTests/Main.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,41 +298,49 @@ enum Main:SyncTests
298298
tests.expect(codelink.path.components ..? ["Sloth", "update(_:)"])
299299
tests.expect(codelink.hash?.value ==? .init("4ko57", radix: 36))
300300
}
301-
if let tests:TestGroup = tests / "codelinks" / "legacy-docc"
301+
if let tests:TestGroup = tests / "Codelinks" / "LegacyDocC"
302302
{
303-
if let tests:TestGroup = tests / "slashes",
303+
if let tests:TestGroup = tests / "Slashes",
304304
let codelink:Codelink = .parse("Sloth/Color", for: tests)
305305
{
306306
tests.expect(nil: codelink.filter)
307307
tests.expect(nil: codelink.scope)
308308
tests.expect(codelink.path.components ..? ["Sloth", "Color"])
309309
tests.expect(nil: codelink.hash)
310310
}
311-
if let tests:TestGroup = tests / "filter",
311+
if let tests:TestGroup = tests / "TrailingSlashes",
312+
let codelink:Codelink = .parse("Sloth/Color/", for: tests)
313+
{
314+
tests.expect(nil: codelink.filter)
315+
tests.expect(nil: codelink.scope)
316+
tests.expect(codelink.path.components ..? ["Sloth", "Color"])
317+
tests.expect(nil: codelink.hash)
318+
}
319+
if let tests:TestGroup = tests / "Filter",
312320
let codelink:Codelink = .parse("Sloth/Color-swift.enum", for: tests)
313321
{
314322
tests.expect(codelink.filter ==? .enum)
315323
tests.expect(nil: codelink.scope)
316324
tests.expect(codelink.path.components ..? ["Sloth", "Color"])
317325
tests.expect(nil: codelink.hash)
318326
}
319-
if let tests:TestGroup = tests / "hash",
327+
if let tests:TestGroup = tests / "Hash",
320328
let codelink:Codelink = .parse("Sloth/update(_:)-4ko57", for: tests)
321329
{
322330
tests.expect(nil: codelink.filter)
323331
tests.expect(nil: codelink.scope)
324332
tests.expect(codelink.path.components ..? ["Sloth", "update(_:)"])
325333
tests.expect(codelink.hash?.value ==? .init("4KO57", radix: 36))
326334
}
327-
if let tests:TestGroup = tests / "hash" / "minus",
335+
if let tests:TestGroup = tests / "Hash" / "Minus",
328336
let codelink:Codelink = .parse("Sloth/-(_:)-4ko57", for: tests)
329337
{
330338
tests.expect(nil: codelink.filter)
331339
tests.expect(nil: codelink.scope)
332340
tests.expect(codelink.path.components ..? ["Sloth", "-(_:)"])
333341
tests.expect(codelink.hash?.value ==? .init("4KO57", radix: 36))
334342
}
335-
if let tests:TestGroup = tests / "hash" / "slinging" / "slasher",
343+
if let tests:TestGroup = tests / "Hash" / "Slinging" / "Slasher",
336344
let codelink:Codelink = .parse("Sloth//(_:)-4ko57", for: tests)
337345
{
338346
tests.expect(nil: codelink.filter)

Sources/Codelinks/Codelink.Path.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,21 @@ extension Codelink.Path
3737
case (_, "-", nil):
3838
format = .legacy
3939
suffix = .init(.init(codepoints))
40-
// we know we already consumed all remaining input
40+
// We know we already consumed all remaining input.
4141
return
4242

4343
case (.nominal(_, nil), "/", nil):
4444
format = .legacy
45-
fallthrough
45+
46+
// Tolerate trailing slash.
47+
if codepoints.isEmpty
48+
{
49+
return
50+
}
51+
else
52+
{
53+
fallthrough
54+
}
4655

4756
case (.nominal(_, nil), ".", _):
4857
if let next:Component = .init(parsing: &codepoints)

0 commit comments

Comments
 (0)