nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: AlecAivazis/survey
Pull request #246 (2019-08-18 02:36:09)

[FIX] Mismatch a marked item on MultiSelect.
First off, it is a great library.  I have used this library very well.

The issue that i'm using the MultiSelect is that marked items mismatch when a cursor is moving on paginating items.
I have many items, so i should paginate items.

it seems the MultiSelect should compare an index on an option, not index on for-loop(PageEntries). 

please check this. thanks.

AlecAivazis: Thanks for submitting this! Sorry I didn't sooner. Mind adding a test that verifies the behavior?
AlecAivazis: Travis should now be fixed. Mind rebasing and giving it a shot?
gjbae1212: Ok. I will add a rebase and a test.
gjbae1212: @AlecAivazis I have added a rebase and a test. check plz.
AlecAivazis: Looks good! I verified that without the change, the test fails. Not sure how this got passed us for so long

Patch:
diff --git a/multiselect.go b/multiselect.go
index 7d1f1be..59bfa55 100644
--- a/multiselect.go
+++ b/multiselect.go
@@ -57,7 +57,7 @@ var MultiSelectQuestionTemplate = `
   {{- "\n"}}
   {{- range $ix, $option := .PageEntries}}
     {{- if eq $ix $.SelectedIndex }}{{color $.Config.Icons.SelectFocus.Format }}{{ $.Config.Icons.SelectFocus.Text }}{{color "reset"}}{{else}} {{end}}
-    {{- if index $.Checked $ix }}{{color $.Config.Icons.MarkedOption.Format }} {{ $.Config.Icons.MarkedOption.Text }} {{else}}{{color $.Config.Icons.UnmarkedOption.Format }} {{ $.Config.Icons.UnmarkedOption.Text }} {{end}}
+    {{- if index $.Checked $option.Index }}{{color $.Config.Icons.MarkedOption.Format }} {{ $.Config.Icons.MarkedOption.Text }} {{else}}{{color $.Config.Icons.UnmarkedOption.Format }} {{ $.Config.Icons.UnmarkedOption.Text }} {{end}}
     {{- color "reset"}}
     {{- " "}}{{$option.Value}}{{"\n"}}
   {{- end}}


Test patch:
diff --git a/multiselect_test.go b/multiselect_test.go
index 2fae154..ba66917 100644
--- a/multiselect_test.go
+++ b/multiselect_test.go
@@ -31,6 +31,12 @@ func TestMultiSelectRender(t *testing.T) {
 	helpfulPrompt := prompt
 	helpfulPrompt.Help = "This is helpful"
 
+	pagePrompt := MultiSelect{
+		Message:  "Pick your words:",
+		Options:  []string{"foo", "bar", "baz", "buz"},
+		PageSize: 2,
+	}
+
 	tests := []struct {
 		title    string
 		prompt   MultiSelect
@@ -105,6 +111,23 @@ func TestMultiSelectRender(t *testing.T) {
 				"\n",
 			),
 		},
+		{
+			"marked on paginating",
+			pagePrompt,
+			MultiSelectTemplateData{
+				SelectedIndex: 0,
+				PageEntries:   core.OptionAnswerList(pagePrompt.Options)[1:3], /* show unmarked items(bar, baz)*/
+				Checked:       map[int]bool{0: true},                          /* foo marked */
+			},
+			strings.Join(
+				[]string{
+					fmt.Sprintf("%s Pick your words:  [Use arrows to move, space to select, type to filter]", defaultIcons().Question.Text),
+					fmt.Sprintf("%s %s  bar", defaultIcons().SelectFocus.Text, defaultIcons().UnmarkedOption.Text),
+					fmt.Sprintf("  %s  baz", defaultIcons().UnmarkedOption.Text),
+				},
+				"\n",
+			),
+		},
 	}
 
 	for _, test := range tests {
Repository: AlecAivazis/survey
Pull request #330 (2021-01-16 09:54:05)

fix(transform): fix nil returned by TransformString
TranformString should not return `nil` on zero value, otherwise `nil` will be passed to next Tranformer if there are more than 1 Transformer in ComposeTransformers.

In next TranformString, while checking if if value is zero at https://github.com/AlecAivazis/survey/blob/e64d9b644fb7d85d69cd3e33a92a43ee706c1b6f/validate.go#L86

`reflect.ValueOf(nil).Interface()` and `reflect.Zero(reflect.ValueOf(nil).Type()).Interface()`will cause program to panic

To fix:
return zero value of string (`""`) instead coz String Tranformer is guaranteed to return string

fix https://github.com/AlecAivazis/survey/issues/329

AlecAivazis: Nice catch! Thanks for submitting a fix

Patch:
diff --git a/transform.go b/transform.go
index ccc75e0..58d5193 100644
--- a/transform.go
+++ b/transform.go
@@ -18,18 +18,21 @@ func TransformString(f func(s string) string) Transformer {
 	return func(ans interface{}) interface{} {
 		// if the answer value passed in is the zero value of the appropriate type
 		if isZero(reflect.ValueOf(ans)) {
-			// skip this `Transformer` by returning a nil value.
+			// skip this `Transformer` by returning a zero value of string.
 			// The original answer will be not affected,
 			// see survey.go#L125.
-			return nil
+			// A zero value of string should be returned to be handled by
+			// next Transformer in a composed Tranformer,
+			// see tranform.go#L75
+			return ""
 		}
 
 		// "ans" is never nil here, so we don't have to check that
-		// see survey.go#L97 for more.
+		// see survey.go#L338 for more.
 		// Make sure that the the answer's value was a typeof string.
 		s, ok := ans.(string)
 		if !ok {
-			return nil
+			return ""
 		}
 
 		return f(s)


Test patch:
diff --git a/transform_test.go b/transform_test.go
index 5d58ee0..4610140 100644
--- a/transform_test.go
+++ b/transform_test.go
@@ -41,4 +41,10 @@ func TestComposeTransformers(t *testing.T) {
 		// the result should be lowercase.
 		t.Errorf("TestComposeTransformers transformer failed to transform the answer to title->lowercase, expected '%s' but got '%s'.", expected, got)
 	}
+
+	var emptyAns string
+	if expected, got := "", transformer(emptyAns); expected != got {
+		// TransformString transformers should be skipped and return zero value string
+		t.Errorf("TestComposeTransformers transformer failed to skip transforming on optional empty input, expected '%s' but got '%s'.", expected, got)
+	}
 }