Skip to content

Commit

Permalink
#593: escape more data
Browse files Browse the repository at this point in the history
  • Loading branch information
bhecquet committed Feb 5, 2024
1 parent 29c6df3 commit c0acefd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public JSONObject toJson() {
snapshotJson.put("snapshotCheckType", snapshotCheckType.getName());
snapshotJson.put("idImage", (screenshot.getImage() == null || screenshot.getImage().getId() == null) ? JSONObject.NULL: screenshot.getImage().getId());
snapshotJson.put("idHtml", (screenshot.getHtml() == null || screenshot.getHtml().getId() == null) ? JSONObject.NULL: screenshot.getHtml().getId());;
snapshotJson.put("name", name);
snapshotJson.put("title", screenshot.getTitle());
snapshotJson.put("url", screenshot.getLocation());
snapshotJson.put("name", encodeString(name, "json"));
snapshotJson.put("title", encodeString(screenshot.getTitle(), "json"));
snapshotJson.put("url", encodeString(screenshot.getLocation(), "json"));
snapshotJson.put("displayInReport", displayInReport);
snapshotJson.put("type", "snapshot");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void testToJsonWithId() throws IOException {
File tmpImgFile = File.createTempFile("img", ".png");
File tmpHtmlFile = File.createTempFile("html", ".html");
ScreenShot screenshot = new ScreenShot(tmpImgFile, tmpHtmlFile, "");
screenshot.setTitle("title");
screenshot.setTitle("title /");
screenshot.setLocation("http://location");
Snapshot snapshotLogger = new Snapshot(screenshot, "main", SnapshotCheckType.TRUE);
snapshotLogger.getScreenshot().getHtml().setId(2);
Expand All @@ -136,8 +136,8 @@ public void testToJsonWithId() throws IOException {
JSONObject json = snapshotLogger.toJson();

Assert.assertEquals(json.getString("type"), "snapshot");
Assert.assertEquals(json.getString("url"), "http://location");
Assert.assertEquals(json.getString("title"), "title");
Assert.assertEquals(json.getString("url"), "http:\\/\\/location");
Assert.assertEquals(json.getString("title"), "title \\/");
Assert.assertEquals(json.getString("name"), "main");
Assert.assertEquals(json.getInt("idHtml"), 2);
Assert.assertEquals(json.getInt("idImage"), 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ public void testEncodeXml() {
*/
@Test(groups = { "ut" })
public void testToJson() throws IOException {
TestStep step = new TestStep("step1", null, Arrays.asList("foobar"), true);
TestStep step = new TestStep("step1 with args: (https://myserver)", null, Arrays.asList("foobar"), true);
step.addMessage(new TestMessage("everything OK", MessageType.INFO));
step.addAction(new TestAction("action2", false, new ArrayList<>()));

Expand Down Expand Up @@ -744,7 +744,7 @@ public void testToJson() throws IOException {

Assert.assertEquals(stepJson.getString("type"), "step");
Assert.assertTrue(stepJson.isNull("exception"));
Assert.assertEquals(stepJson.getString("name"), "step1");
Assert.assertEquals(stepJson.getString("name"), "step1 with args: (https:\\/\\/myserver)");
Assert.assertEquals(stepJson.getString("status"), "SUCCESS");
Assert.assertEquals(stepJson.getLong("timestamp"), step.getTimestamp().toInstant(ZoneOffset.UTC).toEpochMilli());
Assert.assertEquals(stepJson.getJSONArray("actions").length(), 3);
Expand Down

0 comments on commit c0acefd

Please sign in to comment.