From ef150d0148468f004d5200ce08e8563be70a1709 Mon Sep 17 00:00:00 2001 From: Yauhenikapl Date: Fri, 30 Aug 2024 13:36:40 +0300 Subject: [PATCH 1/2] Invalid AspectModelURN is valid in latest version --- .../esmf/aspectmodel/urn/AspectModelUrn.java | 5 ++++- .../esmf/aspectmodel/urn/AspectModelUrnTest.java | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java b/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java index a0eedea6..d64e7ea3 100644 --- a/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java +++ b/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java @@ -34,7 +34,7 @@ * @see Definition of the URN */ public class AspectModelUrn implements Comparable { - public static final String NAMESPACE_REGEX = "[a-zA-Z][a-zA-Z0-9]{1,62}\\.[a-zA-Z0-9-]{1,63}(\\.[a-zA-Z0-9_-]{1,63})*"; + public static final String NAMESPACE_REGEX = "([a-zA-Z0-9()+,\\-.:=@;$_!*']|%[0-9a-fA-F]{2})+"; public static final String NAMESPACE_REGEX_PART = "[a-zA-Z][a-zA-Z0-9]{1,62}(\\.[a-zA-Z0-9_-]{1,63})*"; public static final Pattern NAMESPACE_PATTERN = Pattern.compile( NAMESPACE_REGEX ); @@ -262,6 +262,9 @@ private static String getName( final boolean isSammUrn, final List urnPa return modelElementName; } if ( MODEL_ELEMENT_TYPES.contains( elementType ) ) { + //Check root model element name before current element name + checkElementName( urnParts.get( ASPECT_NAME_INDEX ), "model element" ); + final String modelElementName = urnParts.get( MODEL_ELEMENT_NAME_INDEX ); checkElementName( modelElementName, elementType.getValue() + " element" ); return modelElementName; diff --git a/core/esmf-aspect-model-urn/src/test/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrnTest.java b/core/esmf-aspect-model-urn/src/test/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrnTest.java index 2226dd9e..b2d97b2c 100644 --- a/core/esmf-aspect-model-urn/src/test/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrnTest.java +++ b/core/esmf-aspect-model-urn/src/test/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrnTest.java @@ -342,4 +342,17 @@ void validNamespaceTest() throws URISyntaxException { assertThat( elementUrnWithDash.getNamespaceMainPart() ).isNotEmpty(); assertThat( elementUrnWithDash.getNamespaceMainPart() ).isEqualTo( "org.eclipse.esmf-test" ); } + + @Test + void invalidModelElementNameTest() throws URISyntaxException { + final URI invalidRootModelElementName = new URI( sammBaseUri + "aspect-model:Er?ors:1.1.0#TestAspect" ); + assertThatExceptionOfType( UrnSyntaxException.class ) + .isThrownBy( () -> AspectModelUrn.fromUrn( invalidRootModelElementName ) ) + .withMessage( "The model element name must match \\p{Alpha}\\p{Alnum}*: Er?ors" ); + + final URI invalidModelElementName = new URI( sammBaseUri + "aspect-model:Er?ors:1.1.0:dummy#TestAspect" ); + assertThatExceptionOfType( UrnSyntaxException.class ) + .isThrownBy( () -> AspectModelUrn.fromUrn( invalidModelElementName ) ) + .withMessage( "The model element name must match \\p{Alpha}\\p{Alnum}*: Er?ors" ); + } } From 0b4bfa8879f69f94a44358417e695da8aebf2695 Mon Sep 17 00:00:00 2001 From: Yauhenikapl Date: Fri, 30 Aug 2024 14:05:38 +0300 Subject: [PATCH 2/2] rollback aspect urn regex --- .../java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java b/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java index d64e7ea3..99da627e 100644 --- a/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java +++ b/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java @@ -34,7 +34,7 @@ * @see Definition of the URN */ public class AspectModelUrn implements Comparable { - public static final String NAMESPACE_REGEX = "([a-zA-Z0-9()+,\\-.:=@;$_!*']|%[0-9a-fA-F]{2})+"; + public static final String NAMESPACE_REGEX = "[a-zA-Z][a-zA-Z0-9]{1,62}\\.[a-zA-Z0-9-]{1,63}(\\.[a-zA-Z0-9_-]{1,63})*"; public static final String NAMESPACE_REGEX_PART = "[a-zA-Z][a-zA-Z0-9]{1,62}(\\.[a-zA-Z0-9_-]{1,63})*"; public static final Pattern NAMESPACE_PATTERN = Pattern.compile( NAMESPACE_REGEX );