Skip to content

Commit 4d24bf8

Browse files
authored
Fixed sketch profile parser crashing in some cases. (#3087)
* Added integration test * Fix: sketch profile parsing bug
1 parent 404ab74 commit 4d24bf8

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

‎internal/arduino/sketch/profiles.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ type Profile struct {
124124

125125
// UsesSystemPlatform checks if this profile requires a system installed platform.
126126
func (p *Profile) RequireSystemInstalledPlatform() bool {
127+
if len(p.Platforms) == 0 {
128+
return true
129+
}
127130
return p.Platforms[0].RequireSystemInstalledPlatform()
128131
}
129132

‎internal/integrationtest/profiles/profiles_test.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,21 @@ func TestProfileSetDefault(t *testing.T) {
392392
require.Error(t, err)
393393
require.Equal(t, "Cannot set inexistent_profile as default profile: Profile 'inexistent_profile' not found\n", string(stderr))
394394
}
395+
396+
func TestProfileLoadingIssue3081(t *testing.T) {
397+
// https://github.com/arduino/arduino-cli/issues/3081
398+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
399+
defer env.CleanUp()
400+
401+
// Init the environment explicitly
402+
_, _, err := cli.Run("core", "update-index")
403+
require.NoError(t, err)
404+
_, _, err = cli.Run("core", "install", "arduino:avr")
405+
require.NoError(t, err)
406+
407+
// Compile problematic sketch
408+
sk, err := paths.New("testdata", "Issue3081").Abs()
409+
require.NoError(t, err)
410+
_, _, err = cli.Run("compile", sk.String())
411+
require.NoError(t, err)
412+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
profiles:
2+
garage:
3+
fqbn: arduino:avr:uno
4+
default_profile: garage

0 commit comments

Comments
 (0)