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

Getting cookies from HttpClientResponse throws #34220

Closed
long1eu opened this issue Aug 22, 2018 · 11 comments
Closed

Getting cookies from HttpClientResponse throws #34220

long1eu opened this issue Aug 22, 2018 · 11 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-duplicate Closed in favor of an existing report library-io type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@long1eu
Copy link

long1eu commented Aug 22, 2018

RangeError (index): Invalid value: Valid value range is empty: 0

I/flutter (26221): #1      _Cookie._validate (dart:_http/http_headers.dart:989:14)
I/flutter (26221): #2      _Cookie._parseSetCookieValue (dart:_http/http_headers.dart:933:5)
I/flutter (26221): #3      new _Cookie.fromSetCookieValue (dart:_http/http_headers.dart:849:5)
I/flutter (26221): #4      new Cookie.fromSetCookieValue (dart:_http:1112:16)
I/flutter (26221): #5      _HttpClientResponse.cookies.<anonymous closure> (dart:_http/http_impl.dart:317:26)
I/flutter (26221): #6      List.forEach (dart:core/runtime/libgrowable_array.dart:275:8)
I/flutter (26221): #7      _HttpClientResponse.cookies (dart:_http/http_impl.dart:316:14)

flutter/flutter#20898

@vsmenon vsmenon added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Aug 22, 2018
@long1eu
Copy link
Author

long1eu commented Aug 30, 2018

is there a way to speed this up? I'm stuck with this and can't upgrade to the newer version of flutter

@qwilbird
Copy link

+1
we are also block by this issue and it is critical for our application.

@sidealice
Copy link

sidealice commented Sep 6, 2018

Invalid value: Valid value range is empty: 0#0

same error and stop to wait for this bug has been fixed

@thebriann
Copy link

+1

@thebriann
Copy link

here is some example code

Future<String> ripWebPage(String url,
      {String postData, String postContentType}) async {
    String userAgent =
        'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)';

    if (url.contains("?")) {
      url = url.substring(0, url.indexOf('?'));
    }
    if (url.contains("#")) {
      url = url.substring(0, url.indexOf('#'));
    }
	List<Cookie> cookieJar;
    var client = new HttpClient();
    client.userAgent = userAgent;
    String retVal;
    var uri = Uri.parse(url);
    if (postData == null) {
      // this means it is a GET.
      retVal = await client
          .getUrl(Uri.parse(url))
          .then((HttpClientRequest request) {
        request.headers.set('Accept-Language', 'en-us');
        request.headers.set('Accept-Encoding', 'gzip, deflate');
        request.headers.set('User-Agent', userAgent);
        
        return request.close();
      }).then((HttpClientResponse response) {
        cookieJar = response.cookies;
        return response.transform(utf8.decoder).join();
      });
    }
}

Where you can pass in any URL that would have cookies returning, and cookieJar = response.cookies will return the error that the OP had posted. However, I noticed if you put a breakpoint on that line and wait, response.cookies will return values.

@slightfoot
Copy link
Contributor

Been looking into this with @gerryhigh and we've figured out the below. Was looking into where the exception is being raised dart:_http/http_headers.dart:989:14 code looks like this.

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

Seems its two things, first the length of value should be tested before you try to index -1, and second the check could indicate there is only 1 speech mark in which case you try to get substring(1, 0) which is invalid. I believe testing with the following headers should replicate the issue.

set-cookie: lang=en; path=/
set-cookie: _my_session=somereallylongstring; path=/; HttpOnly
set-cookie: basic_auth=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
set-cookie: basic_auth_checked=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
set-cookie: password=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
set-cookie: visitor_session_id=someid; domain=.mydomain.com; path=/; expires=Sat, 08 Sep 2018 16:54:31 GMT;

@qwilbird
Copy link

+1
is there any progress with this?

@Packetdancer
Copy link

I'm being bitten by this bug as well, and turned up the same result as slightfoot above.

I'd love to contribute a patch since this appears to be a one-line change (and this bug is blocking time-sensitive development), but unfortunately there's not a lot of detail on how best to patch Dart and then bundle it into Flutter to test that patch.

@Andy320
Copy link

Andy320 commented Dec 24, 2018

I wonder if this has been fixed in the latest version? We also came across this issue. Thanks.

@mythz
Copy link

mythz commented May 24, 2019

Ran into this bug using the latest version of flutter:

$ dart --version
Dart VM version: 2.3.1 (Tue May 21 19:28:38 2019 +0200) on "windows_x64"
$ flutter --version
Flutter 1.5.4-hotfix.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 7a4c33425d (3 weeks ago) • 2019-04-29 11:05:24 -0700
Engine • revision 52c7a1e849
Tools • Dart 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

It's very concerning because it's been unresolved for almost a year and you can't guard against it, e.g. this still throws an error:

try {
  if (res.cookies != null && res.cookies.length > 0) {
  }
} on RangeError catch (e) {
  print("RangeError: " + e.toString());
  //ignore https://github.com/dart-lang/sdk/issues/34220
}

@sortie
Copy link
Contributor

sortie commented May 28, 2019

Hi, I fixed this bug (which is a duplicate of #35804) and the fix will be in the next stable release.

@sortie sortie closed this as completed May 28, 2019
@sortie sortie added closed-duplicate Closed in favor of an existing report type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 28, 2019
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. closed-duplicate Closed in favor of an existing report library-io type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

10 participants