Skip to main content

is_valid_gitlab_coordinate

Function is_valid_gitlab_coordinate 

Source
pub fn is_valid_gitlab_coordinate(s: &str) -> bool
Expand description

Whether s is safe to splice into a GitLab API request path and/or is a syntactically well-formed project/component coordinate.

2 or more /-separated segments, each non-empty and drawn from [A-Za-z0-9._-], none of them a ./.. dot segment, and the final segment not ending in .git/.atom.

A syntactic safety gate, not a semantic classifier — it is deliberately not asked to decide whether the first segment is a hostname or a group path, since a hostname’s character set is a subset of the segment charset and both the bare path (org/proj) and the host-qualified name (gitlab.com/org/proj) must pass it. Shared by the fetch-URL gate (crate::client) and the formatter’s display-URL gate (crate::formatter::GitlabCiFormatter), so the two cannot drift apart.

§Examples

use deps_gitlab_ci::host::is_valid_gitlab_coordinate;

assert!(is_valid_gitlab_coordinate("org/project"));
assert!(is_valid_gitlab_coordinate("org/sub/group/project"));
assert!(!is_valid_gitlab_coordinate("org"));
assert!(!is_valid_gitlab_coordinate("org/.."));
assert!(!is_valid_gitlab_coordinate("org/project.git"));