Skip to content

[DNM] Do an experiment for deep recursion of JSON. #1250

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
27 changes: 0 additions & 27 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -145,9 +145,6 @@ let package = Package(
"TestSupport",
"FoundationEssentials"
],
resources: [
.copy("Resources")
],
swiftSettings: availabilityMacros + concurrencyChecking
),

@@ -175,15 +172,6 @@ let package = Package(
] + availabilityMacros + concurrencyChecking
),

.testTarget(
name: "FoundationInternationalizationTests",
dependencies: [
"TestSupport",
"FoundationInternationalization",
],
swiftSettings: availabilityMacros + concurrencyChecking
),

// FoundationMacros
.macro(
name: "FoundationMacros",
@@ -202,18 +190,3 @@ let package = Package(
),
]
)

// https://github.com/apple/swift-package-manager/issues/7174
// Test macro targets result in multiple definitions of `main` on Windows.
#if !os(Windows)
package.targets.append(contentsOf: [
.testTarget(
name: "FoundationMacrosTests",
dependencies: [
"FoundationMacros",
"TestSupport"
],
swiftSettings: availabilityMacros + concurrencyChecking
)
])
#endif
6 changes: 4 additions & 2 deletions Sources/FoundationEssentials/JSON/JSONScanner.swift
Original file line number Diff line number Diff line change
@@ -261,6 +261,8 @@ extension JSONMap.Value {


internal struct JSONScanner {
internal static let maximumRecursionDepth = JSONWriter.maximumRecursionDepth

let options: Options
var reader: DocumentReader
var depth: Int = 0
@@ -412,7 +414,7 @@ internal struct JSONScanner {
mutating func scanArray() throws {
let firstChar = reader.read()
precondition(firstChar == ._openbracket)
guard self.depth < 512 else {
guard self.depth < Self.maximumRecursionDepth else {
throw JSONError.tooManyNestedArraysOrDictionaries(location: reader.sourceLocation(atOffset: 1))
}
self.depth &+= 1
@@ -470,7 +472,7 @@ internal struct JSONScanner {
mutating func scanObject() throws {
let firstChar = self.reader.read()
precondition(firstChar == ._openbrace)
guard self.depth < 512 else {
guard self.depth < Self.maximumRecursionDepth else {
throw JSONError.tooManyNestedArraysOrDictionaries(location: reader.sourceLocation(atOffset: -1))
}
try scanObject(withoutBraces: false)
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/JSON/JSONWriter.swift
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
internal struct JSONWriter {

// Structures with container nesting deeper than this limit are not valid.
private static let maximumRecursionDepth = 512
internal static let maximumRecursionDepth = 512

private var indent = 0
private let pretty: Bool

This file was deleted.

Loading