mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 15:16:07 +00:00
Improve bad Unicode error handling in txt, CSV, and directory handling
This commit is contained in:
@@ -10,6 +10,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
error::SnapshotError,
|
||||||
meta_file::AdjacentMetadata,
|
meta_file::AdjacentMetadata,
|
||||||
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
||||||
};
|
};
|
||||||
@@ -25,9 +26,14 @@ impl SnapshotMiddleware for SnapshotCsv {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let file_name = entry.path().file_name().unwrap().to_string_lossy();
|
let extension = match entry.path().extension() {
|
||||||
|
Some(x) => x
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| SnapshotError::file_name_bad_unicode(entry.path()))?,
|
||||||
|
None => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
if !file_name.ends_with(".csv") {
|
if extension != "csv" {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +41,8 @@ impl SnapshotMiddleware for SnapshotCsv {
|
|||||||
.path()
|
.path()
|
||||||
.file_stem()
|
.file_stem()
|
||||||
.expect("Could not extract file stem")
|
.expect("Could not extract file stem")
|
||||||
.to_string_lossy()
|
.to_str()
|
||||||
|
.ok_or_else(|| SnapshotError::file_name_bad_unicode(entry.path()))?
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let meta_path = entry
|
let meta_path = entry
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
error::SnapshotError,
|
||||||
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
||||||
snapshot_from_imfs, snapshot_from_instance,
|
snapshot_from_imfs, snapshot_from_instance,
|
||||||
};
|
};
|
||||||
@@ -38,7 +39,7 @@ impl SnapshotMiddleware for SnapshotDir {
|
|||||||
.file_name()
|
.file_name()
|
||||||
.expect("Could not extract file name")
|
.expect("Could not extract file name")
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.ok_or_else(|| SnapshotError::file_name_bad_unicode(entry.path()))?
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
Ok(Some(InstanceSnapshot {
|
Ok(Some(InstanceSnapshot {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
error::SnapshotError,
|
||||||
meta_file::AdjacentMetadata,
|
meta_file::AdjacentMetadata,
|
||||||
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
||||||
};
|
};
|
||||||
@@ -25,7 +26,9 @@ impl SnapshotMiddleware for SnapshotTxt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let extension = match entry.path().extension() {
|
let extension = match entry.path().extension() {
|
||||||
Some(x) => x.to_str().unwrap(),
|
Some(x) => x
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| SnapshotError::file_name_bad_unicode(entry.path()))?,
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -38,12 +41,12 @@ impl SnapshotMiddleware for SnapshotTxt {
|
|||||||
.file_stem()
|
.file_stem()
|
||||||
.expect("Could not extract file stem")
|
.expect("Could not extract file stem")
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.ok_or_else(|| SnapshotError::file_name_bad_unicode(entry.path()))?
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let contents = entry.contents(imfs)?;
|
let contents = entry.contents(imfs)?;
|
||||||
let contents_str = str::from_utf8(contents)
|
let contents_str = str::from_utf8(contents)
|
||||||
.expect("File content was not valid UTF-8")
|
.map_err(|err| SnapshotError::file_contents_bad_unicode(err, entry.path()))?
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let properties = hashmap! {
|
let properties = hashmap! {
|
||||||
|
|||||||
Reference in New Issue
Block a user