Permalink
Show file tree
Hide file tree
2 changes: 1 addition & 1 deletion
2
...wer-core/src/main/resources/META-INF/resources/resources/admin/views/adminDashboard.xhtml
2 changes: 1 addition & 1 deletion
2
...-viewer-core/src/main/resources/META-INF/resources/resources/admin/views/adminUsers.xhtml
3 changes: 2 additions & 1 deletion
3
goobi-viewer-core/src/main/resources/META-INF/resources/resources/tags/user/userData.xhtml
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
added nickname validator; html escape existing values when displaying;
refs #24571
- Loading branch information
Andrey Kozhushkov
committed
Mar 23, 2023
1 parent
1376ecf
commit 8eadb32
Showing
5 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
goobi-viewer-core/src/main/java/io/goobi/viewer/faces/validators/NameValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * This file is part of the Goobi viewer - a content presentation and management | ||
| * application for digitized objects. | ||
| * | ||
| * Visit these websites for more information. | ||
| * - http://www.intranda.com | ||
| * - http://digiverso.com | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 2 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| * FOR A PARTICULAR PURPOSE. | ||
| * See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package io.goobi.viewer.faces.validators; | ||
|
|
||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import javax.faces.application.FacesMessage; | ||
| import javax.faces.component.UIComponent; | ||
| import javax.faces.context.FacesContext; | ||
| import javax.faces.validator.FacesValidator; | ||
| import javax.faces.validator.Validator; | ||
| import javax.faces.validator.ValidatorException; | ||
|
|
||
| import io.goobi.viewer.messages.ViewerResourceBundle; | ||
|
|
||
| /** | ||
| * Syntax validator for names (e.g. nickname). | ||
| */ | ||
| @FacesValidator("nameValidator") | ||
| public class NameValidator implements Validator<String> { | ||
|
|
||
| private static final String REGEX = "^[\\w ]+$"; //NOSONAR input size is limited | ||
| private static final Pattern PATTERN = Pattern.compile(REGEX); | ||
|
|
||
| /* (non-Javadoc) | ||
| * @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object) | ||
| */ | ||
| /** {@inheritDoc} */ | ||
| @Override | ||
| public void validate(FacesContext context, UIComponent component, String value) throws ValidatorException { | ||
| if (!validate(value)) { | ||
| FacesMessage msg = new FacesMessage(ViewerResourceBundle.getTranslation("pi_errInvalid", null), ""); | ||
| msg.setSeverity(FacesMessage.SEVERITY_ERROR); | ||
| throw new ValidatorException(msg); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * validateEmailAddress. | ||
| * </p> | ||
| * | ||
| * @param email a {@link java.lang.String} object. | ||
| * @should match correct name | ||
| * @should not match invalid name | ||
| * @return a boolean. | ||
| */ | ||
| public static boolean validate(String name) { | ||
| if (name == null || name.length() > 10_000) { | ||
| return false; | ||
| } | ||
| Matcher m = PATTERN.matcher(name.toLowerCase()); | ||
| return m.find(); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
goobi-viewer-core/src/test/java/io/goobi/viewer/faces/validators/NameValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * This file is part of the Goobi viewer - a content presentation and management | ||
| * application for digitized objects. | ||
| * | ||
| * Visit these websites for more information. | ||
| * - http://www.intranda.com | ||
| * - http://digiverso.com | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 2 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| * FOR A PARTICULAR PURPOSE. | ||
| * See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package io.goobi.viewer.faces.validators; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| public class NameValidatorTest { | ||
|
|
||
| /** | ||
| * @see NameValidator#validate(String) | ||
| * @verifies match correct name | ||
| */ | ||
| @Test | ||
| public void validate_shouldMatchCorrectName() throws Exception { | ||
| Assert.assertTrue(NameValidator.validate("John Doe")); | ||
| } | ||
|
|
||
| /** | ||
| * @see NameValidator#validate(String) | ||
| * @verifies not match invalid name | ||
| */ | ||
| @Test | ||
| public void validate_shouldNotMatchInvalidName() throws Exception { | ||
| Assert.assertTrue(NameValidator.validate("John Doe<script />")); | ||
| } | ||
| } |