Skip to content

Commit 3a24f13

Browse files
committed
Fix library.properties parse error handling
1 parent 384b386 commit 3a24f13

8 files changed

+41
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3030

3131
### Fixed
3232
- Mismatches between library names in `library.properties` and the directory names, which can cause cryptic failures
33+
- `LibraryProperties` skips over parse errors instead of crashing: only lines with non-empty keys and non-nil values are recorded
3334

3435
### Security
3536

lib/arduino_ci/library_properties.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ class LibraryProperties
1111
# @param path [Pathname] The path to the library.properties file
1212
def initialize(path)
1313
@fields = {}
14-
File.foreach(path) do |line|
14+
File.foreach(path) do |line_with_delim|
15+
line = line_with_delim.chomp
1516
parts = line.split("=", 2)
16-
@fields[parts[0]] = parts[1].chomp unless parts.empty?
17+
next if parts[0].nil?
18+
next if parts[0].empty?
19+
next if parts[1].nil?
20+
21+
@fields[parts[0]] = parts[1] unless parts[1].empty?
1722
end
1823
end
1924

spec/library_properties_spec.rb

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RSpec.describe ArduinoCI::LibraryProperties do
44

55
context "property extraction" do
6-
library_properties = ArduinoCI::LibraryProperties.new(Pathname.new(__dir__) + "properties/example.library.properties")
6+
library_properties = ArduinoCI::LibraryProperties.new(Pathname.new(__dir__) + "properties" + "example.library.properties")
77

88
expected = {
99
string: {
@@ -48,5 +48,22 @@
4848
end
4949
end
5050

51+
context "Input handling" do
52+
malformed_examples = [
53+
"extra_blank_line.library.properties",
54+
"just_equals.library.properties",
55+
"no_equals.library.properties",
56+
"no_key.library.properties",
57+
"no_value.library.properties",
58+
].map { |e| Pathname.new(__dir__) + "properties" + e }
59+
60+
malformed_examples.each do |e|
61+
quirk = e.basename.to_s.split(".library.").first
62+
it "reads a properties file with #{quirk}" do
63+
expect { ArduinoCI::LibraryProperties.new(e) }.to_not raise_error
64+
end
65+
end
66+
end
67+
5168

5269
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name=ExtraBlank
2+
3+
sentence=We put the blank line in the middle so overzealous text editors dont trim it
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name=JustEquals
2+
sentence=Bad file with just an equals on a line
3+
=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name=NoEquals
2+
sentence=Bad file with no equals on a line
3+
wat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name=NoKey
2+
sentence=Bad file with no key on a line
3+
=profit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name=NoValue
2+
sentence=Bad file with no value on a line
3+
seriously_why_do_we_even_have_this_line=

0 commit comments

Comments
 (0)