From: Felix Dörre Date: Mon, 4 Jul 2016 08:57:20 +0000 (+0200) Subject: fix: number-format-exception thrown on assurance entry X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=a8a6c492e30d4202e499778b69a5354494f86f84 fix: number-format-exception thrown on assurance entry Change-Id: I5625e53d219360687915b80fb26da6aba1353260 --- diff --git a/src/org/cacert/gigi/pages/wot/AssurePage.java b/src/org/cacert/gigi/pages/wot/AssurePage.java index e0cb4a21..dfd72b7b 100644 --- a/src/org/cacert/gigi/pages/wot/AssurePage.java +++ b/src/org/cacert/gigi/pages/wot/AssurePage.java @@ -2,8 +2,6 @@ package org.cacert.gigi.pages.wot; import java.io.IOException; import java.io.PrintWriter; -import java.sql.Date; -import java.util.Calendar; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; @@ -73,10 +71,10 @@ public class AssurePage extends Page { } try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `users`.`id`, `verified` FROM `users` INNER JOIN `certOwners` ON `certOwners`.`id`=`users`.`id` WHERE `email`=? AND `dob`=? AND `deleted` IS NULL")) { + ds.update(req); + ps.setString(1, req.getParameter("email")); - Calendar c = Calendar.getInstance(); - c.set(Integer.parseInt(req.getParameter("year")), Integer.parseInt(req.getParameter("month")) - 1, Integer.parseInt(req.getParameter("day"))); - ps.setDate(2, new Date(c.getTimeInMillis())); + ps.setDate(2, ds.getDate().toSQLDate()); GigiResultSet rs = ps.executeQuery(); int id = 0; if (rs.next()) { @@ -101,11 +99,12 @@ public class AssurePage extends Page { } } } else { - GigiApiException e = new GigiApiException("I'm sorry, there was no email and date of birth matching" // + throw new GigiApiException("I'm sorry, there was no email and date of birth matching" // + " what you entered in the system. Please double check your information."); - e.format(out, getLanguage(req)); } + } catch (GigiApiException e) { + e.format(out, getLanguage(req)); } } } diff --git a/tests/org/cacert/gigi/pages/wot/TestAssurance.java b/tests/org/cacert/gigi/pages/wot/TestAssurance.java index d626cee0..6a585abd 100644 --- a/tests/org/cacert/gigi/pages/wot/TestAssurance.java +++ b/tests/org/cacert/gigi/pages/wot/TestAssurance.java @@ -53,6 +53,12 @@ public class TestAssurance extends ManagedTest { assertTrue(loc, !loc.contains("type=\"checkbox\" name=\"tos_agree\"")); } + @Test + public void testAssureSearchDobInvalid() throws IOException { + String loc = search("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=1&month=1&year=mal"); + assertNotNull(fetchStartErrorMessage(loc)); + } + @Test public void testAssureSearchDob() throws IOException { String loc = search("email=" + URLEncoder.encode(assureeM, "UTF-8") + "&day=2&month=1&year=1910");