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

TypeError on parsing cookies #234

Closed
YerkoPalma opened this issue Nov 8, 2016 · 3 comments
Closed

TypeError on parsing cookies #234

YerkoPalma opened this issue Nov 8, 2016 · 3 comments

Comments

@YerkoPalma
Copy link

Subject of the issue

x-ray is failling when parsing cookies

Your environment

  • version of node: v4.6.1
  • version of npm: v2.15.9

Steps to reproduce

I run this code

'use strict'
const xray = require('x-ray')()
const URL = 'http://www.senado.cl/appsenado/index.php?mo=senadores&ac=listado'

function senado (options) {
  options = options || {}
  xray(URL, {
    title: 'title'
  })(console.log)
}
senado()
module.exports = senado

Expected behaviour

It should have logged

$ Senado República de Chile - Lista Senadores

Actual behaviour

It throws

/home/ubuntu/workspace/node_modules/x-ray/node_modules/x-ray-crawler/node_modules/superagent/node_modules/cookiejar/cookiejar.js:71
                key = pair[1],
                          ^

TypeError: Cannot read property '1' of null
    at Cookie.parse (/home/ubuntu/workspace/node_modules/x-ray/node_modules/x-ray-crawler/node_modules/superagent/node_modules/cookiejar/cookiejar.js:71:27)
    at new Cookie (/home/ubuntu/workspace/node_modules/x-ray/node_modules/x-ray-crawler/node_modules/superagent/node_modules/cookiejar/cookiejar.js:32:22)
    at /home/ubuntu/workspace/node_modules/x-ray/node_modules/x-ray-crawler/node_modules/superagent/node_modules/cookiejar/cookiejar.js:251:20
    at Array.map (native)
    at CookieJar.setCookies (/home/ubuntu/workspace/node_modules/x-ray/node_modules/x-ray-crawler/node_modules/superagent/node_modules/cookiejar/cookiejar.js:250:27)
    at Agent.saveCookies (/home/ubuntu/workspace/node_modules/x-ray/node_modules/x-ray-crawler/node_modules/superagent/lib/node/agent.js:40:25)
    at emitOne (events.js:77:13)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/home/ubuntu/workspace/node_modules/x-ray/node_modules/x-ray-crawler/node_modules/superagent/lib/node/index.js:921:12)
    at emitNone (events.js:72:20)
@arajeev
Copy link

arajeev commented Mar 8, 2018

@YerkoPalma I'm also facing this issue. Were you able to find a fix to this error?

@bfelbo
Copy link

bfelbo commented Mar 15, 2018

Same here. Any suggestions for how to potentially fix it?

@danielmcq
Copy link

I have put in a PR to help avoid this issue (bmeck/node-cookiejar#34). There are a couple of obstacles which prevent my PR from solving your problem. First, I'm not a maintainer of the https://github.com/bmeck/node-cookiejar project, so I must wait for my fix to get approved and merged. Second, there are still the https://github.com/visionmedia/superagent and https://github.com/matthewmueller/x-ray projects which will need to be updated after to include the fixed version of https://github.com/bmeck/node-cookiejar.

The root cause of this issue is the site in the example (http://www.senado.cl/appsenado/index.php?mo=senadores&ac=listado) is sending back invalid cookies. There are no values in the cookie, just cookie metadata. Below are the headers returned. Notice how the Set-Cookie header has no value, only the HttpOnly and Secure flags. It might be faster to contact the webmaster of the site and tell them that their code is sending invalid cookies. You can read more about the standards for cookies here: https://developer.mozilla.org/ru/docs/Web/HTTP/Headers/Set-Cookie#Directives.

Date: Thu, 19 Apr 2018 02:27:38 GMT
Server: Apache/2.2.23 (Unix)
Access-Control-Allow-Origin: *
Set-Cookie: HttpOnly;Secure
Content-Type: text/html; charset=utf-8
X-Cache: MISS from www.senado.cl
X-Cache-Lookup: HIT from www.senado.cl:80
Via: 1.1 www.senado.cl (squid/3.5.27)
Connection: keep-alive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants