(segments: Vec<&[u8]>)
| 235 | } |
| 236 | |
| 237 | fn resolve_dot_segments(segments: Vec<&[u8]>) -> Result<Vec<Vec<u8>>, CanonicalizeError> { |
| 238 | let mut stack: Vec<Vec<u8>> = Vec::with_capacity(segments.len()); |
| 239 | let last = segments.len().saturating_sub(1); |
| 240 | for (idx, seg) in segments.into_iter().enumerate() { |
| 241 | if seg == b".." { |
| 242 | if stack.pop().is_none() { |
| 243 | return Err(CanonicalizeError::TraversalAboveRoot); |
| 244 | } |
| 245 | if idx == last { |
| 246 | // A trailing `..` leaves a "directory" (trailing slash). |
| 247 | stack.push(Vec::new()); |
| 248 | } |
| 249 | continue; |
| 250 | } |
| 251 | if seg == b"." { |
| 252 | if idx == last { |
| 253 | stack.push(Vec::new()); |
| 254 | } |
| 255 | continue; |
| 256 | } |
| 257 | if seg.is_empty() && idx != last { |
| 258 | // Collapse repeated slashes except at the very end, where an |
| 259 | // empty trailing segment encodes a trailing `/`. |
| 260 | continue; |
| 261 | } |
| 262 | stack.push(seg.to_vec()); |
| 263 | } |
| 264 | Ok(stack) |
| 265 | } |
| 266 | |
| 267 | fn build_canonical_path( |
| 268 | segments: &[Vec<u8>], |
no test coverage detected