mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: potential crash while calling apply_insert if the path is empty
This commit is contained in:
@ -121,14 +121,15 @@ impl DocumentTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply_insert(&mut self, path: &Path, nodes: &[NodeSubTree]) -> Result<(), OTError> {
|
fn apply_insert(&mut self, path: &Path, nodes: &[NodeSubTree]) -> Result<(), OTError> {
|
||||||
|
debug_assert!(!path.is_empty());
|
||||||
|
if path.is_empty() {
|
||||||
|
return Err(OTErrorCode::PathIsEmpty.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let (parent_path, last_path) = path.split_at(path.0.len() - 1);
|
||||||
let parent_path = &path.0[0..(path.0.len() - 1)];
|
let last_index = *last_path.first().unwrap();
|
||||||
let last_index = path.0[path.0.len() - 1];
|
|
||||||
|
|
||||||
|
|
||||||
let parent_node = self
|
let parent_node = self
|
||||||
.node_at_path(&Path(parent_path.to_vec()))
|
.node_at_path(parent_path)
|
||||||
.ok_or_else(|| ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;
|
.ok_or_else(|| ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;
|
||||||
|
|
||||||
self.insert_child_at_index(parent_node, last_index, nodes)
|
self.insert_child_at_index(parent_node, last_index, nodes)
|
||||||
|
@ -39,6 +39,12 @@ impl From<&Vec<usize>> for Path {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&[usize]> for Path {
|
||||||
|
fn from(values: &[usize]) -> Self {
|
||||||
|
Path(values.to_vec())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Path {
|
impl Path {
|
||||||
// delta is default to be 1
|
// delta is default to be 1
|
||||||
|
Reference in New Issue
Block a user