Skip to content

Commit 3a5a1cc

Browse files
committed
Guard against non-positive build code in ContinuousBuildCodeFormatter
Play Store versionCodes must be positive integers, so reject a non-positive derived code.
1 parent 728ec91 commit 3a5a1cc

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/continuous_build_code_formatter.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def build_code(major:, minor:, build_number:)
6565
prefix = (major * 10) + minor
6666
code = (prefix * (10**@build_digits)) + build_number
6767

68+
# Sanity check: Play Store versionCodes must be positive integers.
69+
if code <= 0
70+
UI.user_error!("Derived build code (#{code}) must be a positive integer")
71+
end
72+
6873
if code > MAX_PLAY_STORE_VERSION_CODE
6974
UI.user_error!("Derived build code (#{code}) exceeds the maximum allowed Play Store versionCode (#{MAX_PLAY_STORE_VERSION_CODE})")
7075
end

spec/continuous_build_code_formatter_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979
expect(described_class.new.build_code(major: 210, minor: 0, build_number: 0)).to eq(2_100_000_000)
8080
end
8181

82+
it 'raises when the derived code is not positive (all-zeros input)' do
83+
expect { described_class.new.build_code(major: 0, minor: 0, build_number: 0) }
84+
.to raise_error(/Derived build code \(0\) must be a positive integer/)
85+
end
86+
8287
it 'rejects a non-integer build_digits' do
8388
expect { described_class.new(build_digits: '6') }
8489
.to raise_error(/`build_digits` must be an integer, got: String/)

0 commit comments

Comments
 (0)