Skip to content

Commit

Permalink
Fix: for CSS selectors, the expression is not a predicate
Browse files Browse the repository at this point in the history
We want to have something like:

	response.html('body > h1').html()

The current code is using the CSS expression as if it were a predicate.

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
  • Loading branch information
mem committed Sep 11, 2023
1 parent be167a5 commit 172ea47
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/prober/multihttp/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func buildVars(variable *sm.MultiHttpEntryVariable) string {
b.WriteString(`match ? match[1] || match[0] : null`)

case sm.MultiHttpEntryVariableType_CSS_SELECTOR:
b.WriteString(`response.html().find('`)
b.WriteString(`response.html('`)
b.WriteString(template.JSEscapeString(variable.Expression))
b.WriteString(`')`)
if variable.Attribute == "" {
Expand Down
4 changes: 2 additions & 2 deletions internal/prober/multihttp/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func TestBuildVars(t *testing.T) {
Type: sm.MultiHttpEntryVariableType_CSS_SELECTOR,
Expression: "cssSelector",
},
expected: `vars['name'] = response.html().find('cssSelector').html();`,
expected: `vars['name'] = response.html('cssSelector').html();`,
},
"TestBuildVarsCssSelectorWithAttribute": {
input: sm.MultiHttpEntryVariable{
Expand All @@ -500,7 +500,7 @@ func TestBuildVars(t *testing.T) {
Expression: "cssSelector",
Attribute: "attribute",
},
expected: `vars['name'] = response.html().find('cssSelector').first().attr('attribute');`,
expected: `vars['name'] = response.html('cssSelector').first().attr('attribute');`,
},
}

Expand Down

0 comments on commit 172ea47

Please sign in to comment.