Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallow some special characters in dataset DOI import #4811 #4852

Merged
merged 8 commits into from
Jul 30, 2018
3 changes: 3 additions & 0 deletions src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2020,3 +2020,6 @@ permission.cannotRevokeRole1=Cannot revoke role assignment - you''re missing per
permission.cannotRevokeRole2=Cannot revoke role assignment: {0}
permission.roleSave=Role "{0}" saved
permission.cannotSaveRole=Cannot save role {0}

#GlobalId.java
pid.allowedCharacters=^[A-Za-z0-9._/:\\-]*
20 changes: 18 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/GlobalId.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.BundleUtil;
import static edu.harvard.iq.dataverse.util.StringUtil.isEmpty;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.net.URL;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.ejb.EJB;

/**
Expand Down Expand Up @@ -226,6 +229,19 @@ private boolean checkDOIAuthority(String doiAuthority){

return true;
}



/**
* Verifies that the pid only contains allowed characters.
*
* @param pidParam
* @return true if pid only contains allowed characters false if pid
* contains characters not specified in the allowed characters regex.
*/
public static boolean verifyImportCharacters(String pidParam) {

Pattern p = Pattern.compile(BundleUtil.getStringFromBundle("pid.allowedCharacters"));
Matcher m = p.matcher(pidParam);

return m.matches();
}
}
Loading