diff --git a/pkg/dtd_impl/lib/src/dtd_client.dart b/pkg/dtd_impl/lib/src/dtd_client.dart index 4575d3ce786..2d415d7d2da 100644 --- a/pkg/dtd_impl/lib/src/dtd_client.dart +++ b/pkg/dtd_impl/lib/src/dtd_client.dart @@ -311,6 +311,14 @@ class DTDClient extends Client { // method, forward the request to that client. final combinedName = parameters.method; final dotIndex = combinedName.indexOf('.'); + if (dotIndex == -1) { + // All service methods must have a dot in the name. + throw json_rpc.RpcException( + RpcErrorCodes.kMethodNotFound, + 'Unknown service method: $combinedName', + ); + } + final serviceName = combinedName.substring(0, dotIndex); final methodName = combinedName.substring(dotIndex + 1); diff --git a/pkg/dtd_impl/test/dtd_test.dart b/pkg/dtd_impl/test/dtd_test.dart index eabf9f9d0ab..a1cec582c73 100644 --- a/pkg/dtd_impl/test/dtd_test.dart +++ b/pkg/dtd_impl/test/dtd_test.dart @@ -330,6 +330,21 @@ void main() { ); }); + test('calling a method without a dot', () { + expect( + () => client.sendRequest('abc', {}), + throwsA( + isA() + .having( + (e) => e.code, + 'code', + RpcException.methodNotFound('abc').code, + ) + .having((e) => e.message, 'message', 'Unknown method "abc".'), + ), + ); + }); + test('different clients cannot register the same service', () async { final client2 = _createClient(uri); final registerResult = await client.sendRequest('registerService', {