1616
1717const { TypeValidationError, OperationError } = require ( './errors' ) ;
1818const { normalizeNodeName } = require ( './utils' ) ;
19+ const validator = require ( './validator' ) ;
1920const debug = require ( 'debug' ) ( 'rclnodejs:parameter_event_handler' ) ;
2021
2122const PARAMETER_EVENT_MSG_TYPE = 'rcl_interfaces/msg/ParameterEvent' ;
@@ -251,7 +252,10 @@ class ParameterEventHandler {
251252 }
252253 ) ;
253254 }
254- return this . #resolvePath( nodeName . trim ( ) ) ;
255+
256+ const resolvedNodeName = this . #resolvePath( nodeName . trim ( ) ) ;
257+ this . #validateFullyQualifiedNodePath( resolvedNodeName ) ;
258+ return resolvedNodeName ;
255259 } ) ;
256260
257261 const contentFilter = {
@@ -510,10 +514,6 @@ class ParameterEventHandler {
510514 * @private
511515 */
512516 #resolvePath( nodePath ) {
513- if ( ! nodePath ) {
514- return this . #node. getFullyQualifiedName ( ) ;
515- }
516-
517517 if ( nodePath . startsWith ( '/' ) ) {
518518 return nodePath ;
519519 }
@@ -523,6 +523,22 @@ class ParameterEventHandler {
523523 return resolvedPath . startsWith ( '/' ) ? resolvedPath : `/${ resolvedPath } ` ;
524524 }
525525
526+ /**
527+ * Validate a fully qualified node path before using it in a content filter.
528+ * @private
529+ */
530+ #validateFullyQualifiedNodePath( nodePath ) {
531+ const normalizedPath =
532+ nodePath . length > 1 ? nodePath . replace ( / \/ + $ / , '' ) : nodePath ;
533+ const separatorIndex = normalizedPath . lastIndexOf ( '/' ) ;
534+ const nodeNamespace =
535+ separatorIndex === 0 ? '/' : normalizedPath . slice ( 0 , separatorIndex ) ;
536+ const nodeName = normalizedPath . slice ( separatorIndex + 1 ) ;
537+
538+ validator . validateNamespace ( nodeNamespace ) ;
539+ validator . validateNodeName ( nodeName ) ;
540+ }
541+
526542 /**
527543 * Check if the handler has been destroyed and throw if so.
528544 * @private
0 commit comments