nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: projectdiscovery/goflags
Pull request #83 (2022-10-07 17:34:41)

Fixed runtime map kv parsing regression + tests
Closes https://github.com/projectdiscovery/nuclei/issues/2684


Patch:
diff --git a/runtime_map.go b/runtime_map.go
index c3178a0..c0eaa5a 100644
--- a/runtime_map.go
+++ b/runtime_map.go
@@ -38,7 +38,7 @@ func (runtimeMap *RuntimeMap) Set(value string) error {
 	var k, v string
 	if idxSep := strings.Index(value, kvSep); idxSep > 0 {
 		k = value[:idxSep]
-		v = value[idxSep:]
+		v = value[idxSep+1:]
 	}
 	// note:
 	// - inserting multiple times the same key will override the previous value


Test patch:
diff --git a/runtime_map_test.go b/runtime_map_test.go
new file mode 100644
index 0000000..94f9f83
--- /dev/null
+++ b/runtime_map_test.go
@@ -0,0 +1,16 @@
+package goflags
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/require"
+)
+
+func TestRuntimeMap(t *testing.T) {
+	data := &RuntimeMap{}
+	err := data.Set("variable=value")
+	require.NoError(t, err, "could not set key-value")
+
+	returned := data.AsMap()["variable"]
+	require.Equal(t, "value", returned, "could not get correct return")
+}
Repository: projectdiscovery/goflags
Pull request #101 (2022-11-22 11:43:42)

FileStringSliceOption read the cli input as rawstring if not file
- Add new variable `RawString` to options interface
- option should read the string input as it is from the cli if it is not file
- If it is file then read the file with new line separator 
- FileStringSliceOptions 
    - If file then read the file
    - if not add the input to the slice as it is. 



Patch:
diff --git a/slice_common.go b/slice_common.go
index e09d681..031c233 100644
--- a/slice_common.go
+++ b/slice_common.go
@@ -46,9 +46,14 @@ func ToString(slice []string) string {
 }
 
 type Options struct {
+	// IsFromFile determines if the values are from file
 	IsFromFile func(string) bool
-	IsEmpty    func(string) bool
-	Normalize  func(string) string
+	// IsEmpty determines if the values are empty
+	IsEmpty func(string) bool
+	// Normalize the value (eg. removing trailing spaces)
+	Normalize func(string) string
+	// RawString determines if the value should be considered as is
+	RawString bool
 }
 
 // ToStringSlice converts a value to string slice based on options
@@ -74,6 +79,8 @@ func ToStringSlice(value string, options Options) ([]string, error) {
 		for line := range linesChan {
 			addPartToResult(line)
 		}
+	} else if options.RawString {
+		addPartToResult(value)
 	} else {
 		index := 0
 		for index < len(value) {
@@ -101,7 +108,6 @@ func ToStringSlice(value string, options Options) ([]string, error) {
 			}
 		}
 	}
-
 	return result, nil
 }
 
diff --git a/string_slice_options.go b/string_slice_options.go
index 179b12f..2075a5d 100644
--- a/string_slice_options.go
+++ b/string_slice_options.go
@@ -58,6 +58,7 @@ var FileStringSliceOptions = Options{
 	IsEmpty:    isEmpty,
 	Normalize:  normalizeTrailingParts,
 	IsFromFile: isFromFile,
+	RawString:  true,
 }
 
 // NormalizedStringSliceOptions represents a list of items


Test patch:
diff --git a/string_slice_test.go b/string_slice_test.go
index 5727f18..9a1274a 100644
--- a/string_slice_test.go
+++ b/string_slice_test.go
@@ -1,7 +1,6 @@
 package goflags
 
 import (
-	"fmt"
 	"os"
 	"testing"
 
@@ -46,7 +45,6 @@ func TestNormalizedStringSlicePositive(t *testing.T) {
 
 	for value, expected := range slices {
 		result, err := ToStringSlice(value, NormalizedStringSliceOptions)
-		fmt.Println(result)
 		assert.Nil(t, err)
 		assert.Equal(t, result, expected)
 	}
@@ -96,6 +94,11 @@ func TestFileStringSliceOptions(t *testing.T) {
 	result, err := ToStringSlice(filename, FileStringSliceOptions)
 	assert.Nil(t, err)
 	assert.Equal(t, []string{"value1,value2", "value3"}, result, "could not get correct path")
+
+	// command line input value
+	result, err = ToStringSlice("string:\"contains, comma and quotes.\"", FileStringSliceOptions)
+	assert.Nil(t, err)
+	assert.Equal(t, []string{"string:\"contains, comma and quotes.\""}, result, "could not get correct path")
 }
 
 func TestFileNormalizedOriginalStringSliceOptions(t *testing.T) {
Repository: projectdiscovery/goflags
Pull request #106 (2023-02-15 10:59:31)

Fix EnumVarP func to show default value associated with EnumVariable …
…(#104)


Patch:
diff --git a/goflags.go b/goflags.go
index 9a563a1..215189f 100644
--- a/goflags.go
+++ b/goflags.go
@@ -482,15 +482,20 @@ func (flagSet *FlagSet) EnumVar(field *string, long string, defaultValue EnumVar
 
 // EnumVarP adds a enum flag with a shortname and longname
 func (flagSet *FlagSet) EnumVarP(field *string, long, short string, defaultValue EnumVariable, usage string, allowedTypes AllowdTypes) *FlagData {
+	var hasDefaultValue bool
 	for k, v := range allowedTypes {
 		if v == defaultValue {
+			hasDefaultValue = true
 			*field = k
 		}
 	}
+	if !hasDefaultValue {
+		panic("undefined default value")
+	}
 	flagData := &FlagData{
 		usage:        usage,
 		long:         long,
-		defaultValue: defaultValue,
+		defaultValue: *field,
 	}
 	if short != "" {
 		flagData.short = short


Test patch:
diff --git a/enum_var_test.go b/enum_var_test.go
index 3e7eafe..4bc0927 100644
--- a/enum_var_test.go
+++ b/enum_var_test.go
@@ -18,7 +18,7 @@ const (
 
 func TestEnumVarPositive(t *testing.T) {
 	flagSet := NewFlagSet()
-	flagSet.EnumVar(&enumString, "enum", Nil, "enum", AllowdTypes{"type1": Type1, "type2": Type2})
+	flagSet.EnumVar(&enumString, "enum", Type1, "enum", AllowdTypes{"type1": Type1, "type2": Type2})
 	os.Args = []string{
 		os.Args[0],
 		"--enum", "type1",
diff --git a/goflags_test.go b/goflags_test.go
index 1c8bb22..91b9243 100644
--- a/goflags_test.go
+++ b/goflags_test.go
@@ -86,6 +86,7 @@ func TestUsageOrder(t *testing.T) {
 	var stringSliceData2 StringSlice
 	var intData int
 	var boolData bool
+	var enumData string
 
 	flagSet.SetGroup("String", "String")
 	flagSet.StringVar(&stringData, "string-value", "", "String example value example").Group("String")
@@ -111,6 +112,13 @@ func TestUsageOrder(t *testing.T) {
 	flagSet.BoolVar(&boolData, "bool-with-default-value", true, "Bool with default value example").Group("Bool")
 	flagSet.BoolVarP(&boolData, "bool-with-default-value2", "bwdv", true, "Bool with default value example #2").Group("Bool")
 
+	flagSet.SetGroup("Enum", "Enum")
+	flagSet.EnumVarP(&enumData, "enum-with-default-value", "en", EnumVariable(0), "Enum with default value(zero/one/two)", AllowdTypes{
+		"zero": EnumVariable(0),
+		"one":  EnumVariable(1),
+		"two":  EnumVariable(2),
+	}).Group("Enum")
+
 	output := &bytes.Buffer{}
 	flagSet.CommandLine.SetOutput(output)
 
@@ -145,6 +153,8 @@ BOOLEAN:
    -bv, -bool-value2                 Bool value example #2
    -bool-with-default-value          Bool with default value example (default true)
    -bwdv, -bool-with-default-value2  Bool with default value example #2 (default true)
+ENUM:
+   -en, -enum-with-default-value value  Enum with default value(zero/one/two) (default zero)
 `
 	assert.Equal(t, expected, actual)