@@ -221,14 +221,14 @@ extension FigmaExportCommand {
221221
222222 // Download files to user's temp directory
223223 logger. info ( " Downloading remote files... " )
224- let remoteFiles = images. flatMap { asset -> [ FileContents ] in
225- let lightFiles = makeRemoteFiles (
224+ let remoteFiles = try images. flatMap { asset -> [ FileContents ] in
225+ let lightFiles = try makeRemoteFiles (
226226 images: asset. light. images,
227227 dark: false ,
228228 outputDirectory: tempDirectoryURL
229229 )
230- let darkFiles = asset. dark. flatMap { darkImagePack -> [ FileContents ] in
231- makeRemoteFiles ( images: darkImagePack. images, dark: true , outputDirectory: tempDirectoryURL)
230+ let darkFiles = try asset. dark. flatMap { darkImagePack -> [ FileContents ] in
231+ try makeRemoteFiles ( images: darkImagePack. images, dark: true , outputDirectory: tempDirectoryURL)
232232 } ?? [ ]
233233 return lightFiles + darkFiles
234234 }
@@ -284,9 +284,12 @@ extension FigmaExportCommand {
284284 /// - images: Dictionary of images. Key = scale, value = image info
285285 /// - dark: Dark mode?
286286 /// - outputDirectory: URL of the output directory
287- private func makeRemoteFiles( images: [ Image ] , dark: Bool , outputDirectory: URL ) -> [ FileContents ] {
288- images. map { image -> FileContents in
289- let fileURL = URL ( string: " \( image. name) . \( image. format) " ) !
287+ private func makeRemoteFiles( images: [ Image ] , dark: Bool , outputDirectory: URL ) throws -> [ FileContents ] {
288+ try images. map { image -> FileContents in
289+ guard let name = image. name. addingPercentEncoding ( withAllowedCharacters: . urlPathAllowed) ,
290+ let fileURL = URL ( string: " \( name) . \( image. format) " ) else {
291+ throw FigmaExportError . invalidFileName ( image. name)
292+ }
290293 let scale = image. scale. value
291294 let dest = Destination (
292295 directory: outputDirectory
0 commit comments