nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: roboll/helmfile
Pull request #2081 (2022-02-08 11:20:59)

enable get() to be used with alias $.StateValues


Patch:
diff --git a/pkg/tmpl/get_or_nil.go b/pkg/tmpl/get_or_nil.go
index 72d9b5e..4a216e4 100644
--- a/pkg/tmpl/get_or_nil.go
+++ b/pkg/tmpl/get_or_nil.go
@@ -38,6 +38,10 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
 	var v interface{}
 	var ok bool
 	switch typedObj := obj.(type) {
+	case *map[string]interface{}:
+		obj = *typedObj
+	}
+	switch typedObj := obj.(type) {
 	case map[string]interface{}:
 		v, ok = typedObj[keys[0]]
 		if !ok {


Test patch:
diff --git a/pkg/tmpl/get_or_nil_test.go b/pkg/tmpl/get_or_nil_test.go
index e3eb100..54f30bd 100644
--- a/pkg/tmpl/get_or_nil_test.go
+++ b/pkg/tmpl/get_or_nil_test.go
@@ -53,6 +53,26 @@ func TestGetMap(t *testing.T) {
 	}
 }
 
+func TestGetMapPtr(t *testing.T) {
+	obj := map[string]interface{}{"Foo": map[string]interface{}{"Bar": "Bar"}}
+	objPrt := &obj
+
+	v1, err := get("Foo.Bar", objPrt)
+
+	if err != nil {
+		t.Errorf("unexpected error: %v", err)
+	}
+	if v1 != "Bar" {
+		t.Errorf("unexpected value for path Foo.Bar in %v: expected=Bar, actual=%v", objPrt, v1)
+	}
+
+	_, err = get("Foo.baz", objPrt)
+
+	if err == nil {
+		t.Errorf("expected error but was not occurred")
+	}
+}
+
 func TestGet_Default(t *testing.T) {
 	obj := map[string]interface{}{"Foo": map[string]interface{}{}, "foo": 1}
Repository: robertkrimen/otto
Pull request #440 (2022-09-05 12:27:59)

Fix timeout on empty loop (with unit test)
added unit test for PR #374 

rafaelcn: Quite interesting! If I were a maintainer, I would approve this PR. 

Patch:
diff --git a/cmpl_evaluate_statement.go b/cmpl_evaluate_statement.go
index e16c6ac..056d795 100644
--- a/cmpl_evaluate_statement.go
+++ b/cmpl_evaluate_statement.go
@@ -259,6 +259,17 @@ resultBreak:
 				break
 			}
 		}
+
+		// this is to prevent for cycles with no body from running forever
+		if len(body) == 0 && self.otto.Interrupt != nil {
+			runtime.Gosched()
+			select {
+			case value := <-self.otto.Interrupt:
+				value()
+			default:
+			}
+		}
+
 		for _, node := range body {
 			value := self.cmpl_evaluate_nodeStatement(node)
 			switch value.kind {


Test patch:
diff --git a/otto_test.go b/otto_test.go
index cdbf95c..fc30cd6 100644
--- a/otto_test.go
+++ b/otto_test.go
@@ -2,10 +2,14 @@ package otto
 
 import (
 	"bytes"
+	"errors"
+	"fmt"
 	"io"
 	"testing"
+	"time"
 
 	"github.com/robertkrimen/otto/parser"
+	"github.com/stretchr/testify/require"
 )
 
 func TestOtto(t *testing.T) {
@@ -1738,6 +1742,56 @@ func Test_stackLimit(t *testing.T) {
 	})
 }
 
+func TestOttoInterrupt(t *testing.T) {
+	tests := []struct {
+		name   string
+		script string
+	}{
+		{
+			name:   "empty-for-loop",
+			script: "for(;;) {}",
+		},
+		{
+			name:   "empty-do-while",
+			script: "do{} while(true)",
+		},
+	}
+
+	halt := errors.New("interrupt")
+	for _, tc := range tests {
+		t.Run(tc.name, func(t *testing.T) {
+			vm := New()
+			vm.Interrupt = make(chan func(), 1)
+			ec := make(chan error, 1)
+			go func() {
+				defer func() {
+					if caught := recover(); caught != nil {
+						if caught == halt {
+							fmt.Println(caught)
+							ec <- nil
+							return
+						}
+						panic(caught)
+					}
+				}()
+				_, err := vm.Run(tc.script)
+				ec <- err
+			}()
+
+			// Give the vm chance to execute the loop.
+			time.Sleep(time.Millisecond * 100)
+			vm.Interrupt <- func() { panic(halt) }
+
+			select {
+			case <-time.After(time.Second):
+				t.Fatal("timeout")
+			case err := <-ec:
+				require.NoError(t, err)
+			}
+		})
+	}
+}
+
 func BenchmarkNew(b *testing.B) {
 	for i := 0; i < b.N; i++ {
 		New()
Repository: robertkrimen/otto
Pull request #477 (2022-12-05 22:42:25)

fix: missing regexp capture panic
Fix RegExp panic when a capture doesn't match but the full expression does.


Patch:
diff --git a/builtin_regexp.go b/builtin_regexp.go
index f96078d..0430344 100644
--- a/builtin_regexp.go
+++ b/builtin_regexp.go
@@ -67,11 +67,17 @@ func builtinRegExpTest(call FunctionCall) Value {
 	var start int
 	n := 1
 	re := call.runtime.global.RegExp
+	empty := stringValue("")
 	for i, v := range result[2:] {
 		if i%2 == 0 {
 			start = v
 		} else {
-			re.defineProperty(fmt.Sprintf("$%d", n), stringValue(target[start:v]), 0o100, false)
+			if v == -1 {
+				// No match for this part.
+				re.defineProperty(fmt.Sprintf("$%d", n), empty, 0o100, false)
+			} else {
+				re.defineProperty(fmt.Sprintf("$%d", n), stringValue(target[start:v]), 0o100, false)
+			}
 			n++
 			if n == 10 {
 				break
@@ -81,7 +87,6 @@ func builtinRegExpTest(call FunctionCall) Value {
 
 	if n <= 9 {
 		// Erase remaining.
-		empty := stringValue("")
 		for i := n; i <= 9; i++ {
 			re.defineProperty(fmt.Sprintf("$%d", i), empty, 0o100, false)
 		}


Test patch:
diff --git a/issue_test.go b/issue_test.go
index de1cdce..a64d960 100644
--- a/issue_test.go
+++ b/issue_test.go
@@ -1048,6 +1048,11 @@ func Test_issue317(t *testing.T) {
 			regexp: "(1+)-(2+)-(3+)-(4+)-(5+)-(6+)-(7+)-(8+)-(9+)-(X+)",
 			want:   "",
 		},
+		"missing-match": {
+			input:  "data:image/png;base64,",
+			regexp: "^data:(.*?)(;(.*?))??(;base64)?,",
+			want:   "data:image/png;base64,,image/png,,,;base64,,,,,",
+		},
 	}
 
 	previous := ",,,,,,,,,"