8000 [DO NOT MERGE] Add tests showing problematic meta-key exposure by lynchsft · Pull Request #448 · jpsim/Yams · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[DO NOT MERGE] Add tests showing problematic meta-key exposure #448

New issue

Have a question abo 8000 ut 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

Merged
merged 3 commits into from
May 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion Tests/YamsTests/AnchorCodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,67 @@
""" )
}

func testMetaPropertyKeyExposure_anchors() throws {
let string = """
&foo
someInt: 120
someString: beep

"""

try _testMetaPropertyKeyExposure(source: string)
}

func testMetaPropertyKeyExposure_tags() throws {
let string = """
!<simple>
someInt: 120
someString: beep

"""

try _testMetaPropertyKeyExposure(source: string)
}

func testMetaPropertyKeyExposure_tags_and_anchors() throws {
let string = """
!<simple>
&foo
someInt: 120
someString: beep

"""
try _testMetaPropertyKeyExposure(source: string)
}

private func _testMetaPropertyKeyExposure(source: String) throws {
struct KeyCountAssertingStruct: Codable {
var someInt: Int
var someString: String

init(someInt: Int, someString: String) {
self.someInt = someInt
self.someString = someString
}
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.someInt = try container.decode(Int.self, forKey: .someInt)
self.someString = try container.decode(String.self, forKey: .someString)

XCTAssertEqual(container.allKeys.count, 2)
}
}

let decoded = try YAMLDecoder().decode(KeyCountAssertingStruct.self, from: source)
XCTAssertEqual(decoded.someInt, 120)
XCTAssertEqual(decoded.someString, "beep")

let dict = try YAMLDecoder().decode([String: String].self, from: source)
XCTAssertEqual(dict["someInt"], "120")
XCTAssertEqual(dict["someString"], "beep")
XCTAssertEqual(dict.keys.count, 2)
}

/// A type used to contain values used during testing
private struct SimplePair<First: SimpleProtocol, Second: SimpleProtocol>: Hashable, Codable {
let first: First
Expand All @@ -348,7 +409,7 @@
var intValue: IntegerValue { get }
}

private struct SimpleWithAnchor: SimpleProtocol, YamlAnchorProviding {
private struct SimpleWithAnchor: SimpleProtocol, YamlAnchorCoding {
let nested: NestedStruct
let intValue: Int
var yamlAnchor: Anchor? = "simple"
Expand All @@ -375,7 +436,7 @@
#if swift(>=6.0)
extension Int: @retroactive RawRepresentable {}
#else
extension Int: RawRepresentable {}

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.3

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.3

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.3

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.3

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.3

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.3

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.0

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.0

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.0

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.0

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.0

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future

Check warning on line 439 in Tests/YamsTests/AnchorCodingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 15 with Xcode 16.0

extension declares a conformance of imported type 'Int' to imported protocol 'RawRepresentable'; this will not behave correctly if the owners of 'Swift' introduce this conformance in the future
#endif
extension Int {
public var rawValue: Int { self }
Expand Down
Loading
0