Don't sanitize config names when reading.
Before this fix, opening a tulsigen that had a space in it would
cause an unhelpful error to appear, failing to edit the config or
generate an Xcode project based on that config.
PiperOrigin-RevId: 192283660
diff --git a/src/Tulsi/TulsiGeneratorConfigDocument.swift b/src/Tulsi/TulsiGeneratorConfigDocument.swift
index b75aaf3..304b55d 100644
--- a/src/Tulsi/TulsiGeneratorConfigDocument.swift
+++ b/src/Tulsi/TulsiGeneratorConfigDocument.swift
@@ -232,8 +232,16 @@
return doc
}
- static func urlForConfigNamed(_ name: String, inFolderURL folderURL: URL?) -> URL? {
- let filename = TulsiGeneratorConfig.sanitizeFilename("\(name).\(TulsiGeneratorConfig.FileExtension)")
+ static func urlForConfigNamed(_ name: String,
+ inFolderURL folderURL: URL?,
+ sanitized: Bool = true) -> URL? {
+ let expectedFilename = "\(name).\(TulsiGeneratorConfig.FileExtension)"
+ let filename: String
+ if sanitized {
+ filename = TulsiGeneratorConfig.sanitizeFilename(expectedFilename)
+ } else {
+ filename = expectedFilename
+ }
return folderURL?.appendingPathComponent(filename)
}
diff --git a/src/Tulsi/TulsiProjectDocument.swift b/src/Tulsi/TulsiProjectDocument.swift
index e7babfe..3f408fc 100644
--- a/src/Tulsi/TulsiProjectDocument.swift
+++ b/src/Tulsi/TulsiProjectDocument.swift
@@ -341,7 +341,7 @@
childConfigDocuments.remove(doc)
doc.close()
}
- if let url = urlForConfigNamed(name) {
+ if let url = urlForConfigNamed(name, sanitized: false) {
let errorInfo: String?
do {
try fileManager.removeItem(at: url)
@@ -362,9 +362,10 @@
generatorConfigNames = configNames.sorted()
}
- func urlForConfigNamed(_ name: String) -> URL? {
+ func urlForConfigNamed(_ name: String, sanitized: Bool = true) -> URL? {
return TulsiGeneratorConfigDocument.urlForConfigNamed(name,
- inFolderURL: generatorConfigFolderURL)
+ inFolderURL: generatorConfigFolderURL,
+ sanitized: sanitized)
}
/// Asynchronously loads a previously created config with the given name, invoking the given
@@ -379,7 +380,7 @@
/// Sparsely loads a previously created config with the given name. The returned document may have
/// unresolved label references.
func loadSparseConfigDocumentNamed(_ name: String) throws -> TulsiGeneratorConfigDocument {
- guard let configURL = urlForConfigNamed(name) else {
+ guard let configURL = urlForConfigNamed(name, sanitized: false) else {
throw DocumentError.noSuchConfig
}