Skip to content

Commit

Permalink
fix: remove quotes from info text value (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta authored Dec 17, 2024
1 parent b7d2b8d commit f5e25bc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"fmt"
"os"
"path"
"regexp"
"strings"

"github.com/UpCloudLtd/progress/messages"
)

var quotedValueRegex = regexp.MustCompile(`^["'](.*)["']$`)

type PathWarning struct {
path string
err error
Expand Down Expand Up @@ -74,6 +77,10 @@ func ParseOptions(optionsStr string) (string, map[string]string) {
value = items[1]
}

if quotedValueRegex.MatchString(value) {
value = value[1 : len(value)-1]
}

options[key] = value
}

Expand Down
56 changes: 56 additions & 0 deletions utils/files_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package utils_test

import (
"testing"

"github.com/UpCloudLtd/mdtest/utils"
"github.com/stretchr/testify/assert"
)

func TestParseOptions(t *testing.T) {
t.Parallel()

for _, test := range []struct {
name string
input string
expectedLang string
expectedOptions map[string]string
}{
{
name: "plain value",
input: `sh exit_code=313`,
expectedLang: "sh",
expectedOptions: map[string]string{
"exit_code": "313",
},
},
{
name: "quoted value",
input: `py filename="example.py"`,
expectedLang: "py",
expectedOptions: map[string]string{
"filename": "example.py",
},
},
{
name: "empty values",
input: `txt no_value empty_double_quotes="" empty= empty_single_quotes=''`,
expectedLang: "txt",
expectedOptions: map[string]string{
"empty": "",
"no_value": "",
"empty_single_quotes": "",
"empty_double_quotes": "",
},
},
} {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

lang, options := utils.ParseOptions(test.input)
assert.Equal(t, test.expectedLang, lang)
assert.Equal(t, test.expectedOptions, options)
})
}
}

0 comments on commit f5e25bc

Please sign in to comment.