-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that bundle identifiers are valid URL host components #1069
Merged
d-ronnqvist
merged 21 commits into
swiftlang:main
from
d-ronnqvist:validate-bundle-identifier
Nov 21, 2024
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
28b9522
Add bundle identifier type that ensures a valid URL host component
d-ronnqvist 0e62ffc
Use new Identifier type in `DocumentationBundle/Info`
d-ronnqvist b46b5d3
Update code to not use deprecated `Info/identifier` property
d-ronnqvist bfa673b
Use new Identifier type in `DocumentationBundle`
d-ronnqvist 98c6a58
Update code to not use deprecated `identifier` property
d-ronnqvist 399ed9a
Use new Identifier type in `[Unresolved|Resolved]TopicReference`
d-ronnqvist a7310b7
Update code to not use deprecated topic reference `bundleIdentifier` …
d-ronnqvist 221891a
Deprecate `BundleIdentifier` in favor of `DocumentationBundle/Identif…
d-ronnqvist 890e323
Use new Identifier type in `BuildMetadata`
d-ronnqvist 3c56a2d
Use new Identifier type in `AssetReference`
d-ronnqvist 13b11fb
Use new Identifier type in `ResourceReference`
d-ronnqvist 414ef9c
Use new Identifier type in `ConvertServiceFallbackResolver`
d-ronnqvist 61cc5e2
Use new Identifier type in `SerializableLinkResolutionInformation`
d-ronnqvist 5369b1c
Use new Identifier type in `ConvertAction/Indexer`
d-ronnqvist 4805a05
Prefer `bundleID` over `id` for types that scoped inside bundle
d-ronnqvist 0f2f8ef
Merge branch 'main' into validate-bundle-identifier
d-ronnqvist c2442bc
Merge branch 'main' into validate-bundle-identifier
d-ronnqvist 71b27b6
Merge branch 'main' into validate-bundle-identifier
d-ronnqvist 3d063ef
Merge branch 'main' into validate-bundle-identifier
d-ronnqvist f97e6d3
Use `bundleID` instead of `id` for property names outside the bundle
d-ronnqvist 9478d47
Use "bundle id" in local variable in fallback resolver
d-ronnqvist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
d-ronnqvist marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this code change needed as part of this PR? this seems to be handling separate logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the storage that this was accessing to changed from
[String: ExternalDocumentationSource]
to[DocumentationBundle.Identifier: ExternalDocumentationSource]
it needs to map all the keys of the storage to and from keys any read or write access to this deprecated property.