Skip to content

Commit

Permalink
Fixed #4684
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Mar 25, 2019
1 parent 3486957 commit d4119ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.IOException;
import java.util.regex.Pattern;

import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
Expand All @@ -53,8 +52,10 @@ public void decode(FacesContext context, UIComponent component) {
String submittedValue = context.getExternalContext().getRequestParameterMap().get(clientId);

if (submittedValue != null) {
if (!submittedValue.isEmpty()) {
Pattern pattern = translateMaskIntoRegex(context, inputMask);
String mask = inputMask.getMask();

if (!submittedValue.isEmpty() && !mask.isEmpty()) {
Pattern pattern = translateMaskIntoRegex(context, mask);
if (!pattern.matcher(submittedValue).matches()) {
submittedValue = "";
}
Expand All @@ -74,14 +75,10 @@ public void decode(FacesContext context, UIComponent component) {
* ? - Makes the following input optional
*
* @param context The {@link FacesContext}
* @param inputMask The component
* @param mask The mask value of component
* @return The generated {@link Pattern}
*/
protected Pattern translateMaskIntoRegex(FacesContext context, InputMask inputMask) {
String mask = inputMask.getMask();
if (LangUtils.isValueBlank(mask)) {
throw new FacesException("InputMask requires a value for the 'mask' attribute.");
}
protected Pattern translateMaskIntoRegex(FacesContext context, String mask) {
StringBuilder regex = SharedStringBuilder.get(context, SB_PATTERN);
boolean optionalFound = false;

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/primefaces-p.taglib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11557,10 +11557,10 @@
</attribute>
<attribute>
<description>
<![CDATA[Mask template. Required.]]>
<![CDATA[Mask template.]]>
</description>
<name>mask</name>
<required>true</required>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class InputMaskTest {
public void translatePhoneMaskIntoRegex() {
InputMask inputMask = new InputMask();
inputMask.setMask("(999) 999-9999? x99999");
Pattern pattern = new InputMaskRenderer().translateMaskIntoRegex(new FacesContextMock(), inputMask);
Pattern pattern = new InputMaskRenderer().translateMaskIntoRegex(new FacesContextMock(), inputMask.getMask());
Assert.assertEquals("\\([0-9][0-9][0-9]\\) [0-9][0-9][0-9]\\-[0-9][0-9][0-9][0-9] ?x?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?", pattern.pattern());
Assert.assertTrue(pattern.matcher("(012) 345-6789").matches());
}
Expand All @@ -45,7 +45,7 @@ public void translatePhoneMaskIntoRegex() {
public void issue3566() {
InputMask inputMask = new InputMask();
inputMask.setMask("a*9");
Pattern pattern = new InputMaskRenderer().translateMaskIntoRegex(new FacesContextMock(), inputMask);
Pattern pattern = new InputMaskRenderer().translateMaskIntoRegex(new FacesContextMock(), inputMask.getMask());
Assert.assertEquals("[A-Za-z][A-Za-z0-9][0-9]", pattern.pattern());
Assert.assertTrue(pattern.matcher("aX3").matches());
}
Expand Down

0 comments on commit d4119ed

Please sign in to comment.