Skip to content

Commit

Permalink
fix not to replace undefined variables. (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmi committed Dec 8, 2020
1 parent 54089c1 commit 24aed52
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Selenese Runner Java Relase Note
================================

### 3.33.0

* Fix not to replace undefined variables. (#324)

### 3.32.0

* Change not to retry the composite command if an error occurs. (#320)
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/jp/vmi/selenium/selenese/VarsMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ public String replaceVars(boolean isScript, String expr) {
if (prevEnd < nextStart)
result.append(expr.substring(prevEnd, nextStart));
String name = matcher.group("name");
Object rawValue = get(name);
if (isScript)
result.append(new Gson().toJson(rawValue));
else
result.append(SeleniumUtils.convertToString(rawValue));
if (containsKey(name)) {
Object rawValue = get(name);
if (isScript)
result.append(new Gson().toJson(rawValue));
else
result.append(SeleniumUtils.convertToString(rawValue));
} else {
result.append(matcher.group());
}
prevEnd = matcher.end();
}
if (prevEnd < expr.length())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,12 @@ public void testNoReplaceAlertMethod() {

runner.setReplaceAlertMethod(true);
}

@Test
public void issue324() {
assumeNot(PHANTOMJS, HTMLUNIT, IE);
execute("testcase_issue324.side");
assertThat(result, is(instanceOf(Success.class)));
}

}
56 changes: 56 additions & 0 deletions src/test/resources/selenese/testcase_issue324.side
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"id": "e55b5d28-ec31-4401-8d2a-5b7829f36d82",
"version": "2.0",
"name": "test",
"url": "http://localhost/",
"tests": [{
"id": "834b529f-c7fc-4d43-bbdf-0cfabe285c75",
"name": "issue324",
"commands": [{
"id": "839bb8c7-14da-49dd-9554-e593be46fd3e",
"comment": "",
"command": "open",
"target": "http://localhost/",
"targets": [],
"value": ""
}, {
"id": "392e5b60-ed91-445b-9827-001d5695fece",
"comment": "",
"command": "store",
"target": "hello",
"targets": [],
"value": "var_side01"
}, {
"id": "2cdd69da-89eb-4c45-9265-3f4497c8d632",
"comment": "",
"command": "executeScript",
"target": "const var_js = ${var_side01}; return `${var_js} world`;",
"targets": [],
"value": "var_side02"
}, {
"id": "7c5e78e4-f6fd-4a21-8e0b-c8a29633abeb",
"comment": "",
"command": "echo",
"target": "var_side01=${var_side01}, var_side02=${var_side02}",
"targets": [],
"value": ""
}, {
"id": "846d5221-9f82-48f3-8b65-5711614b163f",
"comment": "",
"command": "assert",
"target": "var_side02",
"targets": [],
"value": "hello world"
}]
}],
"suites": [{
"id": "e7b7100f-dcc5-4d14-a6cc-7987a9d6f804",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["834b529f-c7fc-4d43-bbdf-0cfabe285c75"]
}],
"urls": ["http://localhost/"],
"plugins": []
}

0 comments on commit 24aed52

Please sign in to comment.