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

Bug: cookie value may be empty. #35804

Closed
wendux opened this issue Jan 30, 2019 · 3 comments
Closed

Bug: cookie value may be empty. #35804

wendux opened this issue Jan 30, 2019 · 3 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-_http P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@wendux
Copy link

wendux commented Jan 30, 2019

When response cookie's value is empty, dart sdk will cause an exception.

cookie:

Set-Cookie: session=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT

Log

Unhandled exception:
DioError [DioErrorType.DEFAULT]: RangeError (index): Invalid value: Valid value range is empty: 0#0      _StringBase.[] (dart:core/runtime/libstring_patch.dart:237:55)
#1      _Cookie._validate (dart:_http/http_headers.dart:989:14)
#2      _Cookie._parseSetCookieValue (dart:_http/http_headers.dart:933:5)
#3      new _Cookie.fromSetCookieValue (dart:_http/http_headers.dart:849:5)
#4      new Cookie.fromSetCookieValue (dart:_http:1112:16)
#5      CookieManager.onResponse.<anonymous closure> (file:///Users/duwen/Documents/code/dio/example/cookie_jar.dart:29:37)
#6      MappedListIterable.elementAt (dart:_internal/iterable.dart:414:29)
#7      ListIterable.toList (dart:_internal/iterable.dart:219:19)
#8      CookieManager.onResponse (file:///Users/duwen/Documents/code/dio/example/cookie_jar.dart:29:62)
#9      Dio._onResponse.<anonymous closure>.<anonymous closure> (package:dio/src/dio.dart:744:54)
#10     Dio._executeInterceptors (package:dio/src/dio.dart:501:38)
<asynchronous suspension>
#11     Dio._onResponse.<anonymous closure> (package:dio/src/dio.dart:743:47)
#12     Dio._checkIfNeedEnqueue (package:dio/src/dio.dart:785:22)
#13     Dio._onResponse (package:dio/src/dio.dart:742:12)
#14     Dio._makeRequest (package:dio/src/dio.dart:622:18)
<asynchronous suspension>
#15     Dio._request.<anonymous closure>.<anonymous closure> (package:dio/src/dio.dart:532:15)
#16     _RootZone.runUnary (dart:async/zone.dart:1379:54)
#17     _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#18     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#19     Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#20     Future._complete (dart:async/future_impl.dart:476:7)
#21     _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#22     _AsyncAwaitCompleter.complete (dart:async/runtime/libasync_patch.dart:28:18)
#23     _completeOnAsyncReturn (dart:async/runtime/libasync_patch.dart:295:13)
#24     Dio._executeInterceptors (package:dio/src/dio.dart)
<asynchronous suspension>
#25     Dio._request.<anonymous closure> (package:dio/src/dio.dart:524:20)
#26     Dio._checkIfNeedEnqueue (package:dio/src/dio.dart:785:22)
#27     Dio._request (package:dio/src/dio.dart:523:9)
<asynchronous suspension>
#28     Dio.request (package:dio/src/dio.dart:453:12)
<asynchronous suspension>
#29     Dio.get (package:dio/src/dio.dart:74:12)
#30     main (file:///Users/duwen/Documents/code/dio/example/cookie_jar.dart:76:13)
<asynchronous suspension>
#31     _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289:19)
#32     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

#0      Dio.reject.<anonymous closure> (package:dio/src/dio.dart:225:7)
#1      _RootZone.runUnary (dart:async/zone.dart:1379:54)
#2      _FutureListener.handleError (dart:async/future_impl.dart:147:20)
#3      Future._propagateToListeners.handleError (dart:async/future_impl.dart:654:47)
#4      Future._propagateToListeners (dart:async/future_impl.dart:675:24)
#5      Future._completeError (dart:async/future_impl.dart:494:5)
#6      Future._asyncCompleteError.<anonymous closure> (dart:async/future_impl.dart:542:7)
#7      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#8      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#9      _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#10     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)

I have seen the source code, and find this line

if (value[0] == '"' && value[value.length - 1] == '"') {

value is not test whether is empty before using it.

@wendux wendux changed the title Bug: cookie value may be null. Bug: cookie value may be empty. Jan 30, 2019
@a-siva a-siva added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-_http labels Jan 30, 2019
@Realank
Copy link

Realank commented Jan 31, 2019

if (value[0] == '"' && value[value.length - 1] == '"') {

Please add value length check to avoid empty string exception

@jerrywell
Copy link

jerrywell commented Mar 15, 2019

same issue here: #35189

@wendux wendux closed this as completed Apr 22, 2019
@wendux wendux reopened this Apr 22, 2019
@sortie sortie assigned sortie and unassigned zichangg May 22, 2019
@sortie sortie added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 22, 2019
@sortie
Copy link
Contributor

sortie commented May 23, 2019

This bug is now fixed and the fix will appear in the next stable Dart release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-_http P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants