Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

An Arc sidebar that lists an item twice imports instead of crashing Cra

Victor398f29297c95
diff --git a/Sources/Cra/Services/Import/Importers.swift b/Sources/Cra/Services/Import/Importers.swift
index 0694ab4..00672c0 100644
--- a/Sources/Cra/Services/Import/Importers.swift
+++ b/Sources/Cra/Services/Import/Importers.swift
@@ -140,12 +140,19 @@ enum ArcImporter {
static func plan() throws -> ImportPlan {
let url = supportDir.appendingPathComponent("StorableSidebar.json")
guard let data = try? Data(contentsOf: url) else { throw ImportError.notFound("Arc") }
+ return try plan(sidebar: data)
+ }
+
+ /// The plan from a StorableSidebar.json's contents (favicons and profiles still come from
+ /// `supportDir`).
+ static func plan(sidebar data: Data) throws -> ImportPlan {
guard let root = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
let sidebar = root["sidebar"] as? [String: Any],
let containers = sidebar["containers"] as? [[String: Any]] else { throw ImportError.unreadable("Arc's sidebar") }
var plan = ImportPlan(source: "Arc")
guard let main = containers.first(where: { $0["spaces"] != nil }) else { return plan }
- let items = Dictionary(uniqueKeysWithValues: pairs(main["items"]).map { ($0.0, $0.1) })
+ // A damaged file can list an id twice: the later entry wins, as when Arc decodes it.
+ let items = Dictionary(pairs(main["items"]), uniquingKeysWith: { _, later in later })
var spaceTitleByID: [String: String] = [:]
func convert(_ id: String) -> ImportedItem? {
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index be39f88..354f622 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -39,6 +39,7 @@ enum StoreTests {
sharedFavorites()
themePreview()
try arcSpacesWithoutAThemeShareOneDefault()
+ try arcItemListedTwice()
littleWindowProfile()
tidyTabs()
pinHook()
@@ -408,6 +409,33 @@ enum StoreTests {
expect(store.integrityProblems().isEmpty, "and the sidebar stays sound")
}
+ /// An Arc sidebar that lists an item's id twice imports as if it were listed once, the later
+ /// entry winning as in a dictionary decoded from Arc's key-value array. The nightly fuzzer
+ /// found the importer trapping on such a file ("Duplicate values for key") every night from
+ /// 3 Nov 2026.
+ @MainActor
+ private static func arcItemListedTwice() throws {
+ let fixture = URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent("Fixtures/Arc/StorableSidebar.json")
+ let data = try Data(contentsOf: fixture)
+ var root = try JSONSerialization.jsonObject(with: data) as! [String: Any]
+ var sidebar = root["sidebar"] as! [String: Any]
+ var containers = sidebar["containers"] as! [[String: Any]]
+ let main = containers.firstIndex { $0["spaces"] != nil }!
+ var items = containers[main]["items"] as! [Any]
+ let id = items.firstIndex { $0 is String }!
+ // A stale copy of the first item, listed before the real one: the real one must win.
+ var stale = items[id + 1] as! [String: Any]
+ stale["title"] = "Stale copy"
+ items.insert(contentsOf: [items[id], stale], at: id)
+ containers[main]["items"] = items
+ sidebar["containers"] = containers
+ root["sidebar"] = sidebar
+ let twice = try JSONSerialization.data(withJSONObject: root)
+ let once = try ArcImporter.plan(sidebar: data), listedTwice = try ArcImporter.plan(sidebar: twice)
+ expect(String(describing: listedTwice) == String(describing: once),
+ "an item listed twice imports once, as its later entry")
+ }
+
// promise: #30
/// Arc spaces without a `windowTheme` (both in the made-up profile) import with one fixed
/// default, not the next preset each, which shifted every later space's colour (#30).