Apaq / StompDart

A Stomp implementation for Dart heavily inspired by StompJS
Apache License 2.0
8 stars 4 forks source link

Exception: RangeError: In frame.dart then frame body have UTF-8 chars #9

Closed Dumbris closed 10 years ago

Dumbris commented 10 years ago

I have been getting reproducible RangeError exception, during processing message with utf-8 chars.

In frame.dart line 95 body = data.substring(start, start + len);

data string looks correctly in DartEditor debugger, but data.length gives wrong size. See full dump of message below.

I suppose, required to call UTF8.decode() on recieved message. But message must be byte-array in this case. I can't figure out now, where to place UTF8.decode() Dump of message frame

2014.01.19 17:01:41.188 Client  [FINE]: <<< MESSAGE
subscription:/temp-queue/channel.create.queue
destination:/queue/amq.gen-rDlvIN4gY1gr89dpB3jJdw
message-id:T_/temp-queue/channel.create.queue@@session-PBKFd0rAOtkLHPuqIhF-xA@@1
content-length:609

{"id":"01708047-6a81-42f5-85bf-042b3411678e","title":"Развивающий мультик для детей от 11 месяцев до 3 лет","description":"Развивающий мультик для детей от 11 месяцев до 3 лет","items":[{"id":"d71b25f4-9ba9-46d4-b2a5-7e36e4aaa422","title":"","description":"","items":[{"id":"a77e3728-ae39-4c0e-b6a6-e05b0e60665f","title":"Развивающий мультик для детей от 11 месяцев до 3 лет","description":"Развивающий мультик для детей от 11 месяцев до 3 лет"}]}]}
michaelkrog commented 10 years ago

Thanks.. Ill look into it.

michaelkrog commented 10 years ago

Something like this?

  Caught RangeError: value 138
  dart:core-patch/string_patch.dart 234      _StringBase.substring
  package:stompdart/frame.dart 95:28         Frame.unmarshallSingle
  package:stompdart/frame.dart 124:36        Frame.unmarshall
  package:stompdart/stomp.dart 194:43        Client.connect.<fn>
  dart:async/zone.dart 730                   _rootRunUnary
  dart:async/zone.dart 462                   _ZoneDelegate.runUnary
  dart:async/zone.dart 667                   _CustomizedZone.runUnary
  dart:async/zone.dart 582                   _BaseZone.runUnaryGuarded
  dart:async/stream_impl.dart 333            _BufferingStreamSubscription._sendData
  dart:async/stream_impl.dart 585            _DelayedData.perform
  dart:async/stream_impl.dart 701            _StreamImplEvents.handleNext
  dart:async/stream_impl.dart 661            _PendingEvents.schedule.<fn>
  dart:async/zone.dart 719                   _rootRun
  dart:async/zone.dart 453                   _ZoneDelegate.run
  dart:async/zone.dart 663                   _CustomizedZone.run
  dart:async/zone.dart 574                   _BaseZone.runGuarded
  dart:async/zone.dart 599                   _BaseZone.bindCallback.<fn>
  dart:async/zone.dart 723                   _rootRun
  dart:async/zone.dart 453                   _ZoneDelegate.run
  dart:async/zone.dart 663                   _CustomizedZone.run
  dart:async/zone.dart 574                   _BaseZone.runGuarded
  dart:async/zone.dart 599                   _BaseZone.bindCallback.<fn>
  dart:async/schedule_microtask.dart 23      _asyncRunCallbackLoop
  dart:async/schedule_microtask.dart 32      _asyncRunCallback
  dart:isolate-patch/isolate_patch.dart 128  _RawReceivePortImpl._handleMessage
michaelkrog commented 10 years ago

Im wondering how this doesn't cause an error in stomp-websocket as it is basically copied from their source.

They have this in CoffeScript:

if headers['content-length']
      len = parseInt headers['content-length']
      body = ('' + data).substring(start, start + len)
    else
...

Ref: https://github.com/jmesnil/stomp-websocket/blob/master/src/stomp.coffee#L80

Dart counterpart:

if (headers.containsKey("content-length")) {
      int len = int.parse(headers["content-length"]);
      body = data.substring(start, start + len);
    } else {
...

Both data vars are Strings.

michaelkrog commented 10 years ago

The code handling the content-length header when messages are received needs to be reimplemented. I created a new issue for that: https://github.com/Apaq/StompDart/issues/10

Meanwhile I have disabled the content-length header support - but messages should be parsed nicely anyway.

Dumbris commented 10 years ago

Updated version works ok, without exception. Thank you, Michael!