Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Merge: Support plugin version mid-portions with leading zeros.
Browse files Browse the repository at this point in the history
Now supported: 1.02.3.4
Remains unsupported: 01.2.3.4

BUG=460642

Review URL: https://codereview.chromium.org/949573002

Cr-Commit-Position: refs/heads/master@{#317524}
(cherry picked from commit f151249)

Review URL: https://codereview.chromium.org/991883003

Cr-Commit-Position: refs/branch-heads/2311@{#183}
Cr-Branched-From: 09b7de5-refs/heads/master@{#317474}
  • Loading branch information
wfh-chromium committed Mar 9, 2015
1 parent c7d7f5d commit cbf6236
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ bool ParseVersionNumbers(const std::string& version_str,

for (std::vector<std::string>::const_iterator it = numbers.begin();
it != numbers.end(); ++it) {
if (StartsWithASCII(*it, "+", false))
return false;
int num;
if (!StringToInt(*it, &num))
return false;
Expand All @@ -42,8 +44,8 @@ bool ParseVersionNumbers(const std::string& version_str,
if (num > max)
return false;

// This throws out things like +3, or 032.
if (IntToString(num) != *it)
// This throws out leading zeros for the first item only.
if (it == numbers.begin() && IntToString(num) != *it)
return false;

parsed->push_back(static_cast<uint16>(num));
Expand Down
7 changes: 7 additions & 0 deletions base/version_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,22 @@ TEST(VersionTest, GetVersionFromString) {
{".", 0, false},
{" . ", 0, false},
{"0", 1, true},
{"0.", 0, false},
{"0.0", 2, true},
{"65537.0", 0, false},
{"-1.0", 0, false},
{"1.-1.0", 0, false},
{"1,--1.0", 0, false},
{"+1.0", 0, false},
{"1.+1.0", 0, false},
{"1+1.0", 0, false},
{"++1.0", 0, false},
{"1.0a", 0, false},
{"1.2.3.4.5.6.7.8.9.0", 10, true},
{"02.1", 0, false},
{"0.01", 2, true},
{"f.1", 0, false},
{"15.007.20011", 3, true},
};

for (size_t i = 0; i < arraysize(cases); ++i) {
Expand All @@ -77,6 +83,7 @@ TEST(VersionTest, Compare) {
{"1.1", "1.0.1", 1},
{"1.0.0", "1.0", 0},
{"1.0.3", "1.0.20", -1},
{"11.0.10", "15.007.20011", -1},
};
for (size_t i = 0; i < arraysize(cases); ++i) {
Version lhs(cases[i].lhs);
Expand Down

0 comments on commit cbf6236

Please sign in to comment.