Commit 2859d529 authored by guus's avatar guus

Don't use empty strings or single space characters to represent null values....

Don't use empty strings or single space characters to represent null values. Use null values instead. JM-1334 (reviewer: Gato)

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10299 b35dd754-fafc-0310-a699-88a17e54d16e
parent c623c1f5
......@@ -301,9 +301,13 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
email = iqElement.elementText("email");
name = iqElement.elementText("name");
}
if (email == null || "".equals(email)) {
email = " ";
if (email != null && email.matches("\\s*")) {
email = null;
}
if (name != null && name.matches("\\s*")) {
name = null;
}
// So that we can set a more informative error message back, lets test this for
// stringprep validity now.
if (username != null) {
......
......@@ -144,13 +144,13 @@ public class DefaultUserProvider implements UserProvider {
else {
pstmt.setString(3, encryptedPassword);
}
if (name == null) {
if (name == null || name.matches("\\s*")) {
pstmt.setNull(4, Types.VARCHAR);
}
else {
pstmt.setString(4, name);
}
if (email == null) {
if (email == null || email.matches("\\s*")) {
pstmt.setNull(5, Types.VARCHAR);
}
else {
......@@ -287,7 +287,12 @@ public class DefaultUserProvider implements UserProvider {
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_NAME);
pstmt.setString(1, name);
if (name == null || name.matches("\\s*")) {
pstmt.setNull(1, Types.VARCHAR);
}
else {
pstmt.setString(1, name);
}
pstmt.setString(2, username);
pstmt.executeUpdate();
}
......@@ -309,7 +314,12 @@ public class DefaultUserProvider implements UserProvider {
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_EMAIL);
pstmt.setString(1, email);
if (email == null || email.matches("\\s*")) {
pstmt.setNull(1, Types.VARCHAR);
}
else {
pstmt.setString(1, email);
}
pstmt.setString(2, username);
pstmt.executeUpdate();
}
......
......@@ -190,10 +190,14 @@ public class User implements Cacheable, Externalizable, Result {
throw new UnsupportedOperationException("User provider is read-only.");
}
if ((name == null || name.equals("")) && UserManager.getUserProvider().isNameRequired()) {
if (name != null && name.matches("\\s*")) {
name = null;
}
if (name == null && UserManager.getUserProvider().isNameRequired()) {
throw new IllegalArgumentException("User provider requires name.");
}
try {
String originalName = this.name;
UserManager.getUserProvider().setName(username, name);
......@@ -232,7 +236,7 @@ public class User implements Cacheable, Externalizable, Result {
/**
* Returns the email address of the user or <tt>null</tt> if none is defined.
*
* @return the email address of the user or nullif none is defined.
* @return the email address of the user or null if none is defined.
*/
public String getEmail() {
return email;
......@@ -242,6 +246,10 @@ public class User implements Cacheable, Externalizable, Result {
if (UserManager.getUserProvider().isReadOnly()) {
throw new UnsupportedOperationException("User provider is read-only.");
}
if (email != null && email.matches("\\s*")) {
email = null;
}
if (UserManager.getUserProvider().isEmailRequired() && !StringUtils.isValidEmailAddress(email)) {
throw new IllegalArgumentException("User provider requires email address.");
......
......@@ -146,7 +146,7 @@ public class UserManager implements IQResultListener {
catch (StringprepException se) {
throw new IllegalArgumentException("Invalid username: " + username, se);
}
if (provider.isNameRequired() && (name == null || name.equals(""))) {
if (provider.isNameRequired() && (name == null || name.matches("\\s*"))) {
throw new IllegalArgumentException("Invalid or empty name specified with provider that requires name. User: "
+ username + " Name: " + name);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment