Skip to content

Removed usueless extra unquoting #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ require (
github.com/go-errors/errors v1.0.1
github.com/juju/errors v0.0.0-20190207033735-e65537c515d7 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.3.0
)
46 changes: 24 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,43 +245,38 @@ func main() {
}

// FLAG_HARDWARE
if hardwareFolders, err := toSliceOfUnquoted(hardwareFoldersFlag); err != nil {
printCompleteError(err)
} else if len(hardwareFolders) > 0 {
hardwareFolders := toSliceOfUnquoted(hardwareFoldersFlag)
if len(hardwareFolders) > 0 {
ctx.HardwareDirs = paths.NewPathList(hardwareFolders...)
}
if len(ctx.HardwareDirs) == 0 {
printErrorMessageAndFlagUsage(errors.New("Parameter '" + FLAG_HARDWARE + "' is mandatory"))
}

// FLAG_TOOLS
if toolsFolders, err := toSliceOfUnquoted(toolsFoldersFlag); err != nil {
printCompleteError(err)
} else if len(toolsFolders) > 0 {
toolsFolders := toSliceOfUnquoted(toolsFoldersFlag)
if len(toolsFolders) > 0 {
ctx.ToolsDirs = paths.NewPathList(toolsFolders...)
}
if len(ctx.ToolsDirs) == 0 {
printErrorMessageAndFlagUsage(errors.New("Parameter '" + FLAG_TOOLS + "' is mandatory"))
}

// FLAG_LIBRARIES
if librariesFolders, err := toSliceOfUnquoted(librariesFoldersFlag); err != nil {
printCompleteError(err)
} else if len(librariesFolders) > 0 {
librariesFolders := toSliceOfUnquoted(librariesFoldersFlag)
if len(librariesFolders) > 0 {
ctx.OtherLibrariesDirs = paths.NewPathList(librariesFolders...)
}

// FLAG_BUILT_IN_LIBRARIES
if librariesBuiltInFolders, err := toSliceOfUnquoted(librariesBuiltInFoldersFlag); err != nil {
printCompleteError(err)
} else if len(librariesBuiltInFolders) > 0 {
librariesBuiltInFolders := toSliceOfUnquoted(librariesBuiltInFoldersFlag)
if len(librariesBuiltInFolders) > 0 {
ctx.BuiltInLibrariesDirs = paths.NewPathList(librariesBuiltInFolders...)
}

// FLAG_PREFS
if customBuildProperties, err := toSliceOfUnquoted(customBuildPropertiesFlag); err != nil {
printCompleteError(err)
} else if len(customBuildProperties) > 0 {
customBuildProperties := toSliceOfUnquoted(customBuildPropertiesFlag)
if len(customBuildProperties) > 0 {
ctx.CustomBuildProperties = customBuildProperties
}

Expand Down Expand Up @@ -420,16 +415,23 @@ func toExitCode(err error) int {
return 1
}

func toSliceOfUnquoted(value []string) ([]string, error) {
func toSliceOfUnquoted(value []string) []string {
var values []string
for _, v := range value {
v, err := gohasissues.Unquote(v)
if err != nil {
return nil, err
}
values = append(values, v)
values = append(values, unquote(v))
}
return values
}

func unquote(s string) string {
if stringStartsEndsWith(s, "'") || stringStartsEndsWith(s, "\"") {
s = s[1 : len(s)-1]
}
return values, nil
return s
}

func stringStartsEndsWith(s string, c string) bool {
return strings.HasPrefix(s, c) && strings.HasSuffix(s, c)
}

func printCompleteError(err error) {
Expand Down
43 changes: 43 additions & 0 deletions unquote_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of Arduino Builder.
*
* Arduino Builder is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*/

package main

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestStrConvUnquote(t *testing.T) {
require.Equal(t, "ciao", unquote("ciao"))
require.Equal(t, "arduino:avr:uno", unquote("arduino:avr:uno"))
require.Equal(t, "arduino:avr:uno", unquote("\"arduino:avr:uno\""))
require.Equal(t, "arduino:avr:uno", unquote("'arduino:avr:uno'"))
}