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

Fix URL regex marking as invalid legal URL #3789

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.Validator;
import com.google.gwt.core.client.GWT;

import org.eclipse.kapua.app.console.module.api.client.messages.ValidationMessages;

import java.util.MissingResourceException;
Expand Down Expand Up @@ -70,7 +69,7 @@ public enum FieldType {
ALPHANUMERIC("alphanumeric", "^[a-zA-Z0-9_]+$"),
NUMERIC("numeric", "^[+0-9.]+$"),
PACKAGE_VERSION("package_version", "^[a-zA-Z0-9.\\-\\_]*$"),
URL("url", "(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)");
URL("url", "^(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=//]{1,256}\\.[a-zA-Z0-9()//]{2,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this making use of https mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to have a URL without the https with this regex, in fact the first part of it have the trailing ? character (^(https?:\\/\\/)?).

Screenshot 2023-06-09 at 16 44 45


private String name;
private String regex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.google.common.base.MoreObjects;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.KapuaIllegalArgumentException;
import org.eclipse.kapua.commons.model.id.IdGenerator;
import org.eclipse.kapua.commons.model.id.KapuaEid;
import org.eclipse.kapua.commons.util.ArgumentValidator;
Expand Down Expand Up @@ -50,6 +51,7 @@
import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest;

import javax.inject.Singleton;
import java.net.MalformedURLException;
import java.util.Date;

/**
Expand Down Expand Up @@ -143,6 +145,12 @@ public KapuaId downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDown
// Check Access
AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId));

try {
packageDownloadRequest.getUri().toURL();
} catch (MalformedURLException | IllegalArgumentException ignored) {
throw new KapuaIllegalArgumentException("packageDownloadRequest.uri", packageDownloadRequest.getUri().toString());
}

//
// Generate requestId
KapuaId operationId = new KapuaEid(IdGenerator.generate());
Expand Down