forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 18
Reject malformed version strings in ClickHouseVersion parser #1981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
il9ue
wants to merge
4
commits into
Altinity:antalya-26.3
from
il9ue:fix/antalya-26.3/version-parser-strict
+79
−6
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2fab20b
Reject malformed version strings in ClickHouseVersion parser
il9ue 2ce08de
Merge branch 'antalya-26.3' into fix/antalya-26.3/version-parser-strict
il9ue e852852
Merge branch 'antalya-26.3' into fix/antalya-26.3/version-parser-strict
il9ue 833ec10
Merge branch 'antalya-26.3' into fix/antalya-26.3/version-parser-strict
il9ue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #include <gtest/gtest.h> | ||
| #include <compare> | ||
| #include <Common/ClickHouseVersion.h> | ||
| #include <Common/Exception.h> | ||
|
|
||
| using namespace DB; | ||
|
|
||
| /// Canonical, well-formed versions must parse and round-trip through toString() unchanged. | ||
| TEST(ClickHouseVersion, ParsesValidVersions) | ||
| { | ||
| EXPECT_EQ(ClickHouseVersion("26").toString(), "26"); /// single numeric component | ||
| EXPECT_EQ(ClickHouseVersion("26.1").toString(), "26.1"); /// short two-component form | ||
| EXPECT_EQ(ClickHouseVersion("25.3").toString(), "25.3"); /// real-world `compatibility` value | ||
| EXPECT_EQ(ClickHouseVersion("26.3.1.20001").toString(), "26.3.1.20001"); /// full upstream-shaped version | ||
| EXPECT_EQ(ClickHouseVersion("26.1.3.20001.altinityantalya").toString(), | ||
| "26.1.3.20001.altinityantalya"); /// canonical Antalya build string | ||
| } | ||
|
|
||
| /// The suffix handling must stay generic: any single trailing non-numeric token is a valid | ||
| /// suffix, no matter its text or how many numeric components precede it. | ||
| TEST(ClickHouseVersion, ParsesSuffixedVariants) | ||
| { | ||
| EXPECT_EQ(ClickHouseVersion("26.3.1.20001.altinitystable").toString(), | ||
| "26.3.1.20001.altinitystable"); /// different suffix text still accepted | ||
| EXPECT_EQ(ClickHouseVersion("26.3.1.20001.altinityfips").toString(), | ||
| "26.3.1.20001.altinityfips"); /// another suffix variant | ||
| EXPECT_EQ(ClickHouseVersion("26.1.altinityantalya").toString(), | ||
| "26.1.altinityantalya"); /// suffix after only two components (non-canonical, still valid) | ||
| EXPECT_EQ(ClickHouseVersion("26.altinityantalya").toString(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this IS also a malformed input. there is no |
||
| "26.altinityantalya"); /// suffix after a single component | ||
| } | ||
|
|
||
| /// Malformed inputs must fail fast instead of silently parsing to a different version | ||
| TEST(ClickHouseVersion, RejectsMalformedVersions) | ||
| { | ||
| EXPECT_THROW(ClickHouseVersion("26..1"), Exception); /// empty middle component | ||
| EXPECT_THROW(ClickHouseVersion("26.1."), Exception); /// trailing dot -> empty trailing token | ||
| EXPECT_THROW(ClickHouseVersion("26.x.1"), Exception); /// non-numeric token that is not the last token | ||
|
|
||
| EXPECT_THROW(ClickHouseVersion(""), Exception); /// empty string | ||
| EXPECT_THROW(ClickHouseVersion("."), Exception); /// lone separator, no numeric component | ||
| EXPECT_THROW(ClickHouseVersion(".26"), Exception); /// leading dot -> empty first component | ||
| EXPECT_THROW(ClickHouseVersion("26.."), Exception); /// two empty trailing tokens | ||
| EXPECT_THROW(ClickHouseVersion("26.3.1.20001."), Exception);/// trailing dot after a full version | ||
|
|
||
| EXPECT_THROW(ClickHouseVersion("altinityantalya"), Exception); /// suffix with no numeric component at all | ||
| EXPECT_THROW(ClickHouseVersion("26.altinityantalya.1"), Exception); /// suffix is not the last token | ||
| EXPECT_THROW(ClickHouseVersion("26.3.1.20001.altinityantalya.1"), Exception); /// junk token after an otherwise-valid suffix | ||
|
|
||
| EXPECT_THROW(ClickHouseVersion("v26.1"), Exception); /// alphabetic prefix where a number is required | ||
| } | ||
|
|
||
| /// Ordering compares numeric components first (element by element, shorter list is smaller), | ||
| /// then breaks ties on the suffix string lexicographically. | ||
| TEST(ClickHouseVersion, ComparesByComponentsThenSuffix) | ||
| { | ||
| EXPECT_TRUE(ClickHouseVersion("26.1") < ClickHouseVersion("26.2")); | ||
| EXPECT_TRUE(ClickHouseVersion("25.8") < ClickHouseVersion("26.1")); | ||
|
|
||
| /// 26.1 < 26.1.0 (a trailing .0 makes it "greater" -- can be surprising, so pin it) | ||
| EXPECT_TRUE(ClickHouseVersion("26.1") < ClickHouseVersion("26.1.0")); | ||
|
|
||
| /// with equal components, no suffix sorts before any suffix ("" < "altinityantalya") | ||
| EXPECT_TRUE(ClickHouseVersion("26.1.3.20001") < ClickHouseVersion("26.1.3.20001.altinityantalya")); | ||
|
|
||
| /// with equal components, suffixes order lexicographically: "...antalya" < "...stable" | ||
| EXPECT_TRUE(std::is_lt(ClickHouseVersion("26.3.1.20001.altinityantalya") | ||
| <=> ClickHouseVersion("26.3.1.20001.altinitystable"))); | ||
|
|
||
| /// identical strings compare equal | ||
| EXPECT_TRUE(std::is_eq(ClickHouseVersion("26.1.3.20001.altinityantalya") | ||
| <=> ClickHouseVersion("26.1.3.20001.altinityantalya"))); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this also is INVALID. if one is not sure what or why needs to be done -- one has to ask, not do something that does not make sense.