-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restrict semver requirement specification
- Loading branch information
Showing
4 changed files
with
151 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
// Licensed under the Apache License, Version 2.0, with certain conditions. | ||
// Refer to the "LICENSE" file in the root directory for more information. | ||
// | ||
use anyhow::Result; | ||
use anyhow::{anyhow, Result}; | ||
use semver::VersionReq; | ||
|
||
/// Used to parse a pattern like `[email protected]` and return `aaa` and `3.0.0`. | ||
|
@@ -13,6 +13,34 @@ pub fn parse_pkg_name_version_req( | |
) -> Result<(String, VersionReq)> { | ||
let parts: Vec<&str> = pkg_name_version.split('@').collect(); | ||
if parts.len() == 2 { | ||
// Currently, tman uses the Rust semver crate, while the cloud store | ||
// uses the npm semver package. The semver requirement specifications of | ||
// these two packages are not completely identical. For example: | ||
// | ||
// - The Rust semver crate uses "," to separate different ranges, | ||
// whereas the npm semver package uses a space (" ") to separate | ||
// different requirement ranges. | ||
// - The npm semver package uses "||" to unify different ranges, but the | ||
// Rust semver crate does not support this feature. | ||
// | ||
// Since TEN is a cross-language system, it needs to define its own | ||
// semver requirement specification. This specification could follow | ||
// either the Rust or npm format or other spec, but in either case, tman | ||
// or the cloud store would need to make adaptations. | ||
// | ||
// Therefore, the current approach is to simplify the specification to | ||
// only support a single-range semver requirement, which is the common | ||
// subset of both the npm semver package and the Rust semver crate. | ||
if parts[1].contains("||") | ||
|| parts[1].chars().any(|c| c.is_whitespace()) | ||
|| parts[1].contains(",") | ||
{ | ||
return Err(anyhow!( | ||
"Invalid version requirement '{}' in package name version string: contains forbidden characters (||, whitespace, or ,)", | ||
parts[1] | ||
)); | ||
} | ||
|
||
Ok((parts[0].to_string(), VersionReq::parse(parts[1])?)) | ||
} else { | ||
Ok((pkg_name_version.to_string(), VersionReq::STAR)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters