nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: CloudyKit/jet
Pull request #149 (2020-05-26 14:21:33)

recover from panics that happen when evaluating an expression inside isset()
Previously, code like
```
{{ bla := map() }}
{{ if isset(bla.foo[0].bar)}}
    true
{{else}}
    false
{{end}}
```
would produce a panic, because `bla.foo[0].bar` is parsed as a chain node consisting of `bla.foo[0]` as base and `.bar` as the single field. evalChainNodeExpression() then evaluated `bla.foo[0]` as an index expression using evalPrimaryExpressionGroup(), which would result in a panic.

This change recovers from all panics happening during the evaluation of the argument to isset().

(The duplication of logic between isSet() and evalPrimaryExpressionGroup() is a continued source of bugs and inconsitencies and I'd like to try and get rid of it in the long term by making isSet() a simple wrapper around evalPrimaryExpressionGroup() with the recover code from this change.)


Patch:
diff --git a/eval.go b/eval.go
index 641a9d4..eadc759 100644
--- a/eval.go
+++ b/eval.go
@@ -650,7 +650,14 @@ func notNil(v reflect.Value) bool {
 	}
 }
 
-func (st *Runtime) isSet(node Node) bool {
+func (st *Runtime) isSet(node Node) (ok bool) {
+	defer func() {
+		if r := recover(); r != nil {
+			// something panicked while evaluating node
+			ok = false
+		}
+	}()
+
 	nodeType := node.Type()
 
 	switch nodeType {


Test patch:
diff --git a/eval_test.go b/eval_test.go
index 2f4dfed..9015134 100644
--- a/eval_test.go
+++ b/eval_test.go
@@ -553,6 +553,10 @@ func TestEvalBuiltinExpression(t *testing.T) {
 	RunJetTest(t, data, nil, "IsSetExpression_11", `{{isset(foo.bar)}}`, "false")
 	RunJetTest(t, data, nil, "IsSetExpression_12", `{{isset(foo.asd.foo)}}`, "false")
 	RunJetTest(t, data, nil, "IsSetExpression_13", `{{isset(foo.asd.bar.xyz)}}`, "false")
+	data.Set(
+		"foo", map[string]interface{}{},
+	)
+	RunJetTest(t, data, nil, "IsSetExpression_14", `{{isset(foo.asd[0].bar)}}`, "false")
 }
 
 func TestEvalAutoescape(t *testing.T) {
Repository: CloudyKit/jet
Pull request #188 (2021-01-03 22:54:17)

fix issue #187


Patch:
diff --git a/lex.go b/lex.go
index 31ac111..dc37b6c 100644
--- a/lex.go
+++ b/lex.go
@@ -287,7 +287,14 @@ func (l *lexer) run() {
 // state functions
 func lexText(l *lexer) stateFn {
 	for {
-		if i := strings.IndexByte(l.input[l.pos:], l.leftDelim[0]); i == -1 {
+		// without breaking the API, this seems like a reasonable workaround to correctly parse comments
+		i := strings.IndexByte(l.input[l.pos:], l.leftDelim[0])  // index of suspected left delimiter
+		ic := strings.IndexByte(l.input[l.pos:], leftComment[0]) // index of suspected left comment marker
+		if ic > -1 && ic < i {                                   // use whichever is lower for future lexing
+			i = ic
+		}
+		// if no token is found, skip till the end of template
+		if i == -1 {
 			l.pos = Pos(len(l.input))
 			break
 		} else {


Test patch:
diff --git a/testData/custom_delimiters.jet b/testData/custom_delimiters.jet
index 751bca8..00d92ad 100644
--- a/testData/custom_delimiters.jet
+++ b/testData/custom_delimiters.jet
@@ -1,4 +1,4 @@
-[[ . ]]
+{* comment *}[[ . ]]
 [[ singleValue ]]
 [[ nil ]]
 [[ "" ]]
Repository: ClusterLabs/ha_cluster_exporter
Pull request #86 (2019-10-31 13:24:49)

Change DRBD percent from int to Float
The percentage value generated on `drbdsetup` tool can present a float value depending on the DRBD version. Using float should work for all situations.


Patch:
diff --git a/doc/metric_spec.md b/doc/metric_spec.md
index 64b46de..fb3f4cc 100644
--- a/doc/metric_spec.md
+++ b/doc/metric_spec.md
@@ -206,7 +206,7 @@ The total number of lines for this metric will be the cardinality of `resource`
 
 #### Descriptions
 
-The DRBD disk connections in sync percentage. Values from 0 to 100.
+The DRBD disk connections in sync percentage. Values are float from `0` to `100.00`.
 
 ### `ha_cluster_drbd_resources`
 
diff --git a/drbd_metrics.go b/drbd_metrics.go
index e474b7d..4d9806f 100644
--- a/drbd_metrics.go
+++ b/drbd_metrics.go
@@ -24,9 +24,9 @@ type drbdStatus struct {
 		PeerNodeID  int    `json:"peer-node-id"`
 		PeerRole    string `json:"peer-role"`
 		PeerDevices []struct {
-			Volume        int    `json:"volume"`
-			PeerDiskState string `json:"peer-disk-state"`
-			PercentInSync int    `json:"percent-in-sync"`
+			Volume        int     `json:"volume"`
+			PeerDiskState string  `json:"peer-disk-state"`
+			PercentInSync float64 `json:"percent-in-sync"`
 		} `json:"peer_devices"`
 	} `json:"connections"`
 }


Test patch:
diff --git a/drbd_metrics_test.go b/drbd_metrics_test.go
index 8f88355..9505607 100644
--- a/drbd_metrics_test.go
+++ b/drbd_metrics_test.go
@@ -103,7 +103,7 @@ func TestDrbdParsing(t *testing.T) {
             "unacked": 0,
             "has-sync-details": false,
             "has-online-verify-details": false,
-            "percent-in-sync": 100
+            "percent-in-sync": 99.8
           }
         ]
       }
@@ -142,7 +142,11 @@ func TestDrbdParsing(t *testing.T) {
 	}
 
 	if 100 != drbdDevs[0].Connections[0].PeerDevices[0].PercentInSync {
-		t.Errorf("PercentInSync doesn't correspond! fail got %d", drbdDevs[0].Connections[0].PeerDevices[0].PercentInSync)
+		t.Errorf("PercentInSync doesn't correspond! fail got %f", drbdDevs[0].Connections[0].PeerDevices[0].PercentInSync)
+	}
+
+	if 99.8 != drbdDevs[1].Connections[0].PeerDevices[0].PercentInSync {
+		t.Errorf("Float PercentInSync doesn't correspond! fail got %f", drbdDevs[1].Connections[0].PeerDevices[0].PercentInSync)
 	}
 
 }
Repository: ClusterLabs/ha_cluster_exporter
Pull request #154 (2020-05-04 15:07:15)

fix corosync membership parsing
This PR fixes the regexes used to match corosync membership information, which wouldn't correctly parse node names containing dots.


Patch:
diff --git a/collector/corosync/parser.go b/collector/corosync/parser.go
index 2bd6da1..7c42c0c 100644
--- a/collector/corosync/parser.go
+++ b/collector/corosync/parser.go
@@ -193,7 +193,7 @@ func parseMembers(quorumToolOutput []byte) (members []Member, err error) {
 	   		1          1 192.168.125.24
 	   		2          1 192.168.125.25 (local)
 	*/
-	sectionRE := regexp.MustCompile(`(?m)Membership information\n-+\s+Nodeid\s+Votes\s+Name\n((?:\w+\s+\d+\s[\w-]+(?:\s\(local\))?\n?)+)`)
+	sectionRE := regexp.MustCompile(`(?m)Membership information\n-+\s+Nodeid\s+Votes\s+Name\n+((?:.*\n?)+)`)
 	sectionMatch := sectionRE.FindSubmatch(quorumToolOutput)
 	if sectionMatch == nil {
 		return nil, errors.New("could not find membership information")
@@ -203,7 +203,7 @@ func parseMembers(quorumToolOutput []byte) (members []Member, err error) {
 	/*
 		1          1 192.168.125.24 (local)
 	*/
-	linesRE := regexp.MustCompile(`(?m)(?P<node_id>\w+)\s+(?P<votes>\d+)\s(?P<name>[\w-]+)(?:\s(?P<local>\(local\)))?\n?`)
+	linesRE := regexp.MustCompile(`(?m)(?P<node_id>\w+)\s+(?P<votes>\d+)\s(?P<name>[\w-\.]+)(?:\s(?P<local>\(local\)))?\n?`)
 	linesMatches := linesRE.FindAllSubmatch(sectionMatch[1], -1)
 	for _, match := range linesMatches {
 		matches := extractRENamedCaptureGroups(linesRE, match)


Test patch:
diff --git a/collector/corosync/parser_test.go b/collector/corosync/parser_test.go
index ebdcc62..1d0502d 100644
--- a/collector/corosync/parser_test.go
+++ b/collector/corosync/parser_test.go
@@ -194,3 +194,42 @@ func TestParseMembersUintError(t *testing.T) {
 	assert.Contains(t, err.Error(), "could not parse vote number to uint64")
 	assert.Contains(t, err.Error(), "value out of range")
 }
+
+func TestParseMembersWithAnotherExample(t *testing.T) {
+	quorumToolOutput := []byte(`Quorum information
+------------------
+Date:             Mon May  4 16:50:13 2020
+Quorum provider:  corosync_votequorum
+Nodes:            2
+Node ID:          2
+Ring ID:          1/8
+Quorate:          Yes
+
+Votequorum information
+----------------------
+Expected votes:   2
+Highest expected: 2
+Total votes:      2
+Quorum:           1  
+Flags:            2Node Quorate WaitForAll 
+
+Membership information
+----------------------
+    Nodeid      Votes Name
+         1          1 192.168.127.20
+         2          1 192.168.127.21 (local)`)
+
+	members, err := parseMembers(quorumToolOutput)
+
+	assert.NoError(t, err)
+
+	assert.Len(t, members, 2)
+	assert.Exactly(t, "1", members[0].Id)
+	assert.Exactly(t, "192.168.127.20", members[0].Name)
+	assert.False(t, members[0].Local)
+	assert.EqualValues(t, 1, members[0].Votes)
+	assert.Exactly(t, "2", members[1].Id)
+	assert.Exactly(t, "192.168.127.21", members[1].Name)
+	assert.True(t, members[1].Local)
+	assert.EqualValues(t, 1, members[1].Votes)
+}