Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentType with utf-8 not encoded properly in Dart 3.6 #59719

Closed
tomyeh opened this issue Dec 16, 2024 · 5 comments
Closed

ContentType with utf-8 not encoded properly in Dart 3.6 #59719

tomyeh opened this issue Dec 16, 2024 · 5 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@tomyeh
Copy link

tomyeh commented Dec 16, 2024

When servicing the following code, it'll throw an exception, Latin1Codec.encode. Looks like the encoding is not used properly

It happens only in Dart 3.6.0. It works fine with 3.5.x.

import "dart:io";

void main() {
  HttpServer
  .bind(InternetAddress.anyIPv4, 8081)
  .then((server) {
    server.autoCompress = true;
    server.listen((request) {
      request.response
        ..headers.contentType = ContentType("text", "plain", charset: "utf-8")
        ..writeln('日本語')
        ..close();
    });
  });
}

The stack trace:

Invalid argument (string): Contains invalid characters.: "日本語\n"
#0      _UnicodeSubsetEncoder.convert (dart:convert/ascii.dart:85:9)
#1      Latin1Codec.encode (dart:convert/latin1.dart:40:46)
#2      _IOSinkImpl._writeString (dart:_http/http_impl.dart:1064:21)
#3      _IOSinkImpl.writeln (dart:_http/http_impl.dart:1090:5)
#4      main.<anonymous closure>.<anonymous closure> (file:///Users/tomyeh/prj/boeneo/server/test/20807.dart:13:11)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1609:10)
#6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366:11)
#7      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#8      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:777:19)
#9      _StreamController._add (dart:async/stream_controller.dart:651:7)
#10     _StreamController.add (dart:async/stream_controller.dart:606:5)
#11     _HttpServer._handleRequest (dart:_http/http_impl.dart:3339:19)
#12     new _HttpConnection.<anonymous closure> (dart:_http/http_impl.dart:3123:19)
#13     _RootZone.runUnaryGuarded (dart:async/zone.dart:1609:10)
#14     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366:11)
#15     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#16     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:777:19)
#17     _StreamController._add (dart:async/stream_controller.dart:651:7)
#18     _StreamController.add (dart:async/stream_controller.dart:606:5)
#19     _HttpParser._headersEnd (dart:_http/http_parser.dart:390:19)
#20     _HttpParser._doParse (dart:_http/http_parser.dart:759:15)
#21     _HttpParser._parse (dart:_http/http_parser.dart:320:7)
#22     _HttpParser._onData (dart:_http/http_parser.dart:887:5)
#23     _RootZone.runUnaryGuarded (dart:async/zone.dart:1609:10)
#24     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366:11)
#25     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#26     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:777:19)
#27     _StreamController._add (dart:async/stream_controller.dart:651:7)
#28     _StreamController.add (dart:async/stream_controller.dart:606:5)
#29     _Socket._onData (dart:io-patch/socket_patch.dart:2455:41)
#30     _RootZone.runUnaryGuarded (dart:async/zone.dart:1609:10)
#31     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366:11)
#32     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#33     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:777:19)
#34     _StreamController._add (dart:async/stream_controller.dart:651:7)
#35     _StreamController.add (dart:async/stream_controller.dart:606:5)
#36     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1942:33)
#37     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1385:14)
#38     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#39     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#40     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#41     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)
@tomyeh tomyeh added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Dec 16, 2024
@parlough
Copy link
Member

\cc @brianquinlan

@a-siva a-siva added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P2 A bug or feature request we're likely to work on labels Dec 18, 2024
@a-siva a-siva added the triaged Issue has been triaged by sub team label Dec 18, 2024
@brianquinlan
Copy link
Contributor

I can repro this regression.

@brianquinlan
Copy link
Contributor

The regression was introduced by e8c0353#diff-20950a3598c59676d6479c783a26cabfb41b9ae425c455b80ece9384c5d1332dR1072

The fix is straightforward but the behavior here is tricky so I'm going to add a bunch of additional tests.

copybara-service bot pushed a commit that referenced this issue Dec 26, 2024
Bug:#59719
Change-Id: Ie2606b557b1f9f50d52de23c56d36b45e52efda1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402281
Reviewed-by: Alexander Aprelev <[email protected]>
Commit-Queue: Brian Quinlan <[email protected]>
@brianquinlan
Copy link
Contributor

FYI, I've requested that this be cherrypicked into Dart 3.6.1: #59813

@tomyeh
Copy link
Author

tomyeh commented Jan 9, 2025

It seems not part of 3.6.1, is it?

copybara-service bot pushed a commit that referenced this issue Jan 17, 2025
… charset.

Bug:#59719
Change-Id: Ief2f79d98a400f90d2098cd2f3cd8312325c91cb
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/402281
Cherry-pick-request: #59813
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402422
Reviewed-by: Kevin Moore <[email protected]>
Reviewed-by: Alexander Aprelev <[email protected]>
Commit-Queue: Brian Quinlan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants