diff --git a/Sources/XCRemoteCache/Dependencies/DependenciesWriter.swift b/Sources/XCRemoteCache/Dependencies/DependenciesWriter.swift index 1087653..ae5c16d 100644 --- a/Sources/XCRemoteCache/Dependencies/DependenciesWriter.swift +++ b/Sources/XCRemoteCache/Dependencies/DependenciesWriter.swift @@ -50,7 +50,7 @@ public class FileDependenciesWriter: DependenciesWriter { var content = "" for (file, deps) in dependencies { content.append(file + ": ") - content.append(deps.joined(separator: " ")) + content.append(deps.map { $0.replacingOccurrences(of: " ", with: "\\ ") }.joined(separator: " ")) content.append("\n") } try content.write(to: file, atomically: true, encoding: .utf8) diff --git a/Tests/XCRemoteCacheTests/Dependencies/DependenciesWriterTests.swift b/Tests/XCRemoteCacheTests/Dependencies/DependenciesWriterTests.swift new file mode 100644 index 0000000..26c180a --- /dev/null +++ b/Tests/XCRemoteCacheTests/Dependencies/DependenciesWriterTests.swift @@ -0,0 +1,47 @@ +// Copyright (c) 2021 Spotify AB. +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@testable import XCRemoteCache +import XCTest + +class FileDependenciesWriterTests: XCTestCase { + + private func generateTempFileURL(name: String = #function) throws -> URL { + let directory = NSTemporaryDirectory() + return try NSURL.fileURL(withPathComponents: [directory, name]).unwrap() + } + + func testWriteDependencyWithSpace() throws { + let url = try generateTempFileURL() + let writer = FileDependenciesWriter(url, accessor: FileManager.default) + + try writer.writeGeneric(dependencies: [ + "/SomePath/Pods/Target Support Files/lottie-ios/lottie-ios-dummy.m", + ]) + + let expectedContent = """ + dependencies: /SomePath/Pods/Target\\ Support\\ Files/lottie-ios/lottie-ios-dummy.m + + """ + + let content = String(data: try Data(contentsOf: url), encoding: .utf8) + + XCTAssertEqual(content, expectedContent) + } +}