(project_id: &str)
| 649 | } |
| 650 | |
| 651 | pub(crate) fn validate_project_id(project_id: &str) -> std::result::Result<(), &'static str> { |
| 652 | if project_id.is_empty() { |
| 653 | return Err("project_id must not be empty"); |
| 654 | } |
| 655 | if project_id.starts_with('.') |
| 656 | || project_id.contains('/') |
| 657 | || project_id.contains('\\') |
| 658 | || project_id.contains("..") |
| 659 | { |
| 660 | return Err("project_id must be a single safe path segment"); |
| 661 | } |
| 662 | if !project_id |
| 663 | .bytes() |
| 664 | .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'_' | b'-' | b'.')) |
| 665 | { |
| 666 | return Err("project_id contains unsupported characters"); |
| 667 | } |
| 668 | Ok(()) |
| 669 | } |
| 670 | |
| 671 | fn validate_no_nul(path: &Path) -> Result<()> { |
| 672 | if path.to_string_lossy().contains('\0') { |
no test coverage detected