Skip to content

Commit

Permalink
Merge pull request #22 from jiikko/fix-array-sdk-version
Browse files Browse the repository at this point in the history
Don't allow duplicated sdkVersion in AndroidManifest.xml
  • Loading branch information
jmatsu authored Jan 24, 2020
2 parents 60e9f0a + 55aea8d commit 44b4c5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/android_apk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class AndroidApk
# @return [String] Return a file path of this apk file
attr_accessor :filepath

NOT_ALLOW_DUPLICATE_TAG_NAMES = %w(application).freeze
NOT_ALLOW_DUPLICATE_TAG_NAMES = %w(
application
sdkVersion
targetSdkVersion
).freeze

DPI_TO_NAME_MAP = {
120 => "ldpi",
Expand All @@ -104,7 +108,7 @@ class AndroidManifestValidateError < StandardError
# Do analyze the given apk file. Analyzed apk does not mean *valid*.
#
# @param [String] filepath a filepath of an apk to be analyzed
# @raise [AndroidManifestValidateError] if AndroidManifest.xml has multiple application tags.
# @raise [AndroidManifestValidateError] if AndroidManifest.xml has multiple application, sdkVersion tags.
# @return [AndroidApk, nil] An instance of AndroidApk will be returned if no problem exists while analyzing. Otherwise nil.
def self.analyze(filepath)
return nil unless File.exist?(filepath)
Expand Down
7 changes: 7 additions & 0 deletions spec/android_apk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
end
end

context "if duplicated sdk_version apk are given" do
let(:apk_filepath) { File.join(FIXTURE_DIR, "other", "duplicate_sdk_version.apk") }
it "should raise error" do
expect { subject }.to raise_error(AndroidApk::AndroidManifestValidateError, /Duplication of sdkVersion tag is not allowed/)
end
end

context "if invalid sample apk files are given" do
context "no such apk file" do
let(:apk_filepath) { File.join(FIXTURE_DIR, "other", "no_such_file") }
Expand Down
Binary file added spec/fixture/other/duplicate_sdk_version.apk
Binary file not shown.

0 comments on commit 44b4c5c

Please sign in to comment.