Skip to content

Commit

Permalink
Add a validation check for consecutive periods in keyPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Jul 16, 2024
1 parent d85d94e commit a5985e2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ng-appserver/src/main/java/ng/appserver/NGKeyValueAssociation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
}

Expand Down

0 comments on commit a5985e2

Please sign in to comment.