Skip to content

Commit 3f6e44e

Browse files
brettfosachin-sandhu
authored andcommitted
strip BOM from YAML manifests
1 parent 114cd43 commit 3f6e44e

File tree

4 files changed

+7
-31
lines changed

4 files changed

+7
-31
lines changed

docker/lib/dependabot/docker/file_parser.rb

-10
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def parse
5353
end
5454

5555
manifest_files.each do |file|
56-
check_manifest_file_encoding(file)
5756
dependency_set += workfile_file_dependencies(file)
5857
end
5958

@@ -83,15 +82,6 @@ def manifest_files
8382
dependency_files.select { |f| f.type == "file" && f.name.match?(YAML_REGEXP) }
8483
end
8584

86-
sig { params(file: Dependabot::DependencyFile).void }
87-
def check_manifest_file_encoding(file)
88-
return unless file.content&.start_with?("\uFEFF")
89-
90-
file_path = Pathname.new(file.directory).join(file.name).cleanpath.to_path
91-
msg = "The file appears to have been saved with a byte order mark (BOM). This will prevent proper parsing."
92-
raise Dependabot::DependencyFileNotParseable.new(file_path, msg)
93-
end
94-
9585
sig { params(file: Dependabot::DependencyFile).returns(DependencySet) }
9686
def workfile_file_dependencies(file)
9787
dependency_set = DependencySet.new

docker/lib/dependabot/shared/shared_file_fetcher.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ def yamlfiles
7676
@yamlfiles ||= T.let(
7777
repo_contents(raise_errors: false)
7878
.select { |f| f.type == "file" && f.name.match?(YAML_REGEXP) }
79-
.map { |f| fetch_file_from_host(f.name) },
79+
.map do |f|
80+
fetched = fetch_file_from_host(f.name)
81+
# The YAML parser used doesn't properly handle a byte-order-mark (BOM) and it can cause failures in
82+
# unexpected ways. That BOM is removed here to allow regular updates to proceed.
83+
fetched.content = T.must(fetched.content)[1..-1] if fetched.content&.start_with?("\uFEFF")
84+
fetched
85+
end,
8086
T.nilable(T::Array[DependencyFile])
8187
)
8288
end

docker/spec/dependabot/docker/file_parser_spec.rb

-10
Original file line numberDiff line numberDiff line change
@@ -1142,16 +1142,6 @@
11421142
end
11431143
end
11441144
end
1145-
1146-
context "with an invalid yaml file" do
1147-
let(:podfile_fixture_name) { "with_bom.yaml" }
1148-
1149-
it "throws when the yaml starts with a byte order mark" do
1150-
expect do
1151-
_unused = dependencies
1152-
end.to raise_error(Dependabot::DependencyFileNotParseable)
1153-
end
1154-
end
11551145
end
11561146

11571147
describe "YAML parse" do

docker/spec/fixtures/kubernetes/yaml/with_bom.yaml

-10
This file was deleted.

0 commit comments

Comments
 (0)