-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that bundle identifiers are valid URL host components (#1069)
* Add bundle identifier type that ensures a valid URL host component rdar://135335645 * Use new Identifier type in `DocumentationBundle/Info` * Update code to not use deprecated `Info/identifier` property * Use new Identifier type in `DocumentationBundle` * Update code to not use deprecated `identifier` property * Use new Identifier type in `[Unresolved|Resolved]TopicReference` * Update code to not use deprecated topic reference `bundleIdentifier` property * Deprecate `BundleIdentifier` in favor of `DocumentationBundle/Identifier` * Use new Identifier type in `BuildMetadata` * Use new Identifier type in `AssetReference` * Use new Identifier type in `ResourceReference` * Use new Identifier type in `ConvertServiceFallbackResolver` * Use new Identifier type in `SerializableLinkResolutionInformation` * Use new Identifier type in `ConvertAction/Indexer` * Prefer `bundleID` over `id` for types that scoped inside bundle * Use `bundleID` instead of `id` for property names outside the bundle * Use "bundle id" in local variable in fallback resolver
- Loading branch information
1 parent
e0ce789
commit 75344ae
Showing
132 changed files
with
1,144 additions
and
911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Sources/SwiftDocC/Infrastructure/DocumentationBundle+Identifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension DocumentationBundle { | ||
/// A stable and locally unique identifier for a collection of documentation inputs. | ||
public struct Identifier: RawRepresentable { | ||
public let rawValue: String | ||
|
||
public init(rawValue: String) { | ||
// To ensure that the identifier can be used as a valid "host" component of a resolved topic reference's url, | ||
// replace any consecutive sequence of unsupported characters with a "-". | ||
self.rawValue = rawValue | ||
.components(separatedBy: Self.charactersToReplace) | ||
.filter { !$0.isEmpty } | ||
.joined(separator: "-") | ||
} | ||
|
||
private static let charactersToReplace = CharacterSet.urlHostAllowed.inverted | ||
} | ||
} | ||
|
||
extension DocumentationBundle.Identifier: Hashable {} | ||
extension DocumentationBundle.Identifier: Sendable {} | ||
|
||
// Support creating an identifier from a string literal. | ||
extension DocumentationBundle.Identifier: ExpressibleByStringLiteral { | ||
public init(stringLiteral value: StringLiteralType) { | ||
self.init(rawValue: value) | ||
} | ||
} | ||
|
||
// Sort identifiers based on their raw string value. | ||
extension DocumentationBundle.Identifier: Comparable { | ||
public static func < (lhs: Self, rhs: Self) -> Bool { | ||
lhs.rawValue < rhs.rawValue | ||
} | ||
} | ||
|
||
// Print as a single string value | ||
extension DocumentationBundle.Identifier: CustomStringConvertible { | ||
public var description: String { | ||
rawValue | ||
} | ||
} | ||
|
||
// Encode and decode the identifier as a single string value. | ||
extension DocumentationBundle.Identifier: Codable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let rawValue = try container.decode(String.self) | ||
self.init(rawValue: rawValue) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(rawValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.