Skip to content

Commit

Permalink
fix: Fixed IPv6 validation (#5574)
Browse files Browse the repository at this point in the history
* fix: Fixed IPv6 validation

Signed-off-by: MMaiero <[email protected]>

* chore: logging cleanup

Signed-off-by: MMaiero <[email protected]>

---------

Signed-off-by: MMaiero <[email protected]>
  • Loading branch information
MMaiero authored Nov 22, 2024
1 parent 49d787c commit 2d44b65
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.Objects;
import java.util.Optional;
import java.util.logging.Logger;

import org.eclipse.kura.web.client.messages.Messages;
import org.eclipse.kura.web.client.util.HelpButton;
Expand Down Expand Up @@ -163,6 +164,7 @@ interface TabIp6UiUiBinder extends UiBinder<Widget, TabIp6Ui> {

private static TabIp6UiUiBinder uiBinder = GWT.create(TabIp6UiUiBinder.class);
private static final Messages MSGS = GWT.create(Messages.class);
private static final Logger logger = Logger.getLogger(TabIp6Ui.class.getSimpleName());

private boolean dirty = false;
private final NetworkTabsUi tabs;
Expand Down Expand Up @@ -372,12 +374,12 @@ private void initIpField() {
boolean isValid = address != null && address.trim().length() > 0
&& address.trim().matches(IPV6_ADDRESS_REGEX);

if (!isValid) {
this.groupIp.setValidationState(ValidationState.ERROR);
this.wrongInputIp.setText(MSGS.netIPv6InvalidAddress());
} else {
if (isValid) {
this.groupIp.setValidationState(ValidationState.NONE);
this.wrongInputIp.setText("");
} else {
this.groupIp.setValidationState(ValidationState.ERROR);
this.wrongInputIp.setText(MSGS.netIPv6InvalidAddress());
}
});
}
Expand Down Expand Up @@ -660,16 +662,20 @@ private boolean nullOrEmpty(String value) {
public boolean isValid() {
boolean isWan = this.status.getSelectedValue().equals(STATUS_WAN);
boolean isManual = this.configure.getSelectedValue().equals(CONFIGURE_MANUAL);
boolean isValid = true;

if (isWan && isManual) {
if (nullOrEmpty(this.ip.getValue()) || this.subnet.getValue() == null
|| nullOrEmpty(this.gateway.getValue())) {
if (isManual) {
if (nullOrEmpty(this.ip.getValue()) || this.subnet.getValue() == null) {
this.groupIp.setValidationState(ValidationState.ERROR);
this.groupSubnet.setValidationState(ValidationState.ERROR);
this.groupGateway.setValidationState(ValidationState.ERROR);
this.wrongInputIp.setText(MSGS.netIPv6InvalidAddress());
this.wrongInputSubnet.setText(MSGS.netIpv6InvalidSubnet());
isValid = false;
}
if (isWan && nullOrEmpty(this.gateway.getValue())) {
this.groupGateway.setValidationState(ValidationState.ERROR);
this.wrongInputGateway.setText(MSGS.netIPv6InvalidAddress());
return false;
isValid = false;
}
}

Expand All @@ -678,10 +684,10 @@ public boolean isValid() {
|| this.groupSubnet.getValidationState().equals(ValidationState.ERROR)
|| this.groupGateway.getValidationState().equals(ValidationState.ERROR)
|| this.groupDns.getValidationState().equals(ValidationState.ERROR)) {
return false;
isValid = false;
}

return true;
return isValid;
}

@Override
Expand Down

0 comments on commit 2d44b65

Please sign in to comment.