From a5985e2c6da15e015e701ad6b1c82152bdaaeef7 Mon Sep 17 00:00:00 2001 From: Hugi Thordarson Date: Tue, 16 Jul 2024 06:45:03 +0000 Subject: [PATCH] Add a validation check for consecutive periods in keyPaths --- .../ng/appserver/NGKeyValueAssociation.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ng-appserver/src/main/java/ng/appserver/NGKeyValueAssociation.java b/ng-appserver/src/main/java/ng/appserver/NGKeyValueAssociation.java index e923cca0..1f3cf04e 100644 --- a/ng-appserver/src/main/java/ng/appserver/NGKeyValueAssociation.java +++ b/ng-appserver/src/main/java/ng/appserver/NGKeyValueAssociation.java @@ -15,26 +15,31 @@ public NGKeyValueAssociation( final String keyPath ) { /** * FIXME: We should be conducting a more thorough syntax check for every "disallowed" character // Hugi 2024-06-25 + * FIXME: This check really belongs with KVC, not the association // Hugi 2024-07-16 */ private static void validateKeyPath( final String keyPath ) { if( keyPath == null ) { - throw new NGAssociationConstructionException( "An association's keyPath can't be null" ); + throw new NGAssociationConstructionException( "[keyPath] can't be null" ); } if( keyPath.isEmpty() ) { - throw new NGAssociationConstructionException( "An association's keyPath can't be an empty string" ); + throw new NGAssociationConstructionException( "[keyPath] can't be an empty string" ); } if( keyPath.startsWith( "." ) ) { - throw new NGAssociationConstructionException( "An association's keyPath can't start with a period." ); + throw new NGAssociationConstructionException( "[keyPath] can't start with a period." ); } if( keyPath.endsWith( "." ) ) { - throw new NGAssociationConstructionException( "An association's keyPath can't end with a period." ); + throw new NGAssociationConstructionException( "[keyPath] can't end with a period." ); } - if( keyPath.contains( "@" ) ) { - throw new NGAssociationConstructionException( "Our keyPaths don't support keypath operators (keys prefixed with '@')" ); + if( keyPath.contains( ".@" ) ) { + throw new NGAssociationConstructionException( "[keyPath] doesn't support operators (keys prefixed with '@')" ); + } + + if( keyPath.contains( ".." ) ) { + throw new NGAssociationConstructionException( "[keyPath] can't contain two (or more) consecutive periods" ); } }