Merge pull request #151 from ainopara/fix/denpendency-writer-white-space

Escape white space in denpendency writer
This commit is contained in:
Bartosz Polaczyk
2022-06-14 15:25:57 +02:00
committed by GitHub
2 changed files with 48 additions and 1 deletions
@@ -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)
@@ -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)
}
}