Skip to content

Commit 2cae43f

Browse files
committed
SQL: Fix hyphen handling in build metadata in to_semver_no_prerelease() SQL fn
1 parent e85bb86 commit 2cae43f

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE OR REPLACE FUNCTION to_semver_no_prerelease(text) RETURNS semver_triple IMMUTABLE PARALLEL SAFE AS $$
2+
SELECT (
3+
split_part($1, '.', 1)::numeric,
4+
split_part($1, '.', 2)::numeric,
5+
split_part(split_part($1, '+', 1), '.', 3)::numeric
6+
)::semver_triple
7+
WHERE strpos($1, '-') = 0
8+
$$ LANGUAGE SQL;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE OR REPLACE FUNCTION to_semver_no_prerelease(text) RETURNS semver_triple IMMUTABLE PARALLEL SAFE AS $$
2+
SELECT (
3+
split_part($1, '.', 1)::numeric,
4+
split_part($1, '.', 2)::numeric,
5+
split_part(split_part($1, '+', 1), '.', 3)::numeric
6+
)::semver_triple
7+
WHERE strpos(split_part($1, '+', 1), '-') = 0
8+
$$ LANGUAGE SQL;

src/sql.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ mod tests {
8484
test(&mut conn, "1.2.4", Some((1, 2, 4)));
8585
test(&mut conn, "1.2.4+metadata", Some((1, 2, 4)));
8686
test(&mut conn, "1.2.4-beta.3", None);
87-
// TODO: see https://github.com/rust-lang/crates.io/issues/3882
88-
test(&mut conn, "0.4.45+curl-7.78.0", None);
87+
// see https://github.com/rust-lang/crates.io/issues/3882
88+
test(&mut conn, "0.4.45+curl-7.78.0", Some((0, 4, 45)));
8989
test(&mut conn, "0.1.4-preview+4.3.2", None);
9090
}
9191
}

0 commit comments

Comments
 (0)