koa-prerender icon indicating copy to clipboard operation
koa-prerender copied to clipboard

Middleware crashes when no query string is present

Open bibanul opened this issue 11 years ago • 9 comments

Line 104: .parse(options.url, true).query.hasOwnProperty('escaped_fragment')) {

if there's no query this .parse(options.url, true).query will evaluate to undefined and .hasOwnProperty will crash taking down the whole pipeline.

bibanul avatar Dec 04 '14 20:12 bibanul

url.parse(options.url, true).query should not evaluate to undefined. What version of node are you running? If you run the following, do you get undefined?

Open a node repl in your terminal by typing node, then run:

require('url').parse('https://www.google.com', true).query

Can you give an example of a URL that returns undefined for query?

Thanks!

thoop avatar Dec 05 '14 05:12 thoop

Running node 0.11.14. It comes back as undefined.

Thanks, Bogdan

On Dec 4, 2014, at 9:43 PM, Todd Hooper [email protected] wrote:

url.parse(options.url, true).query should not evaluate to undefined. What version of node are you running? If you run the following, do you get undefined?

Open a node repl in your terminal by typing node, then run:

require('url').parse('https://www.google.com', true).query Can you give an example of a URL that returns undefined for query?

Thanks!

— Reply to this email directly or view it on GitHub.

bibanul avatar Dec 05 '14 07:12 bibanul

Interesting. Thanks for that! I'll have to upgrade

thoop avatar Dec 06 '14 05:12 thoop

  xxx GET /?_escaped_fragment_= 500 3ms -

  TypeError: query.hasOwnProperty is not a function

Node: 6.0

leesiongchan avatar May 03 '16 09:05 leesiongchan

Just fixed this in master of https://github.com/prerender/prerender-node

The change should be ported here to remove the hasOwnProperty use since Node v6 removed that from the querystring object.

thoop avatar May 08 '16 19:05 thoop

meet the same problem.

node v6.2.2 "koa": "^1.2.0", "koa-prerender": "^1.0.3", "prerender-node": "^2.7.0",

ghjagus avatar Mar 15 '17 10:03 ghjagus

I have the same problem too.

node v6.10.0 [email protected] [email protected]

please reference this fix, it's work: https://github.com/rainesinternationaldev/koa-prerender/commit/3ebc6ace0f43e405438dacdf6b518a3f3bc35502

visig9 avatar Mar 20 '17 08:03 visig9

I have the same problem "koa": "^2.5.1", "koa-prerender": "^1.0.3",

mylastore avatar Mar 22 '20 05:03 mylastore

This changes will fix the issue:

https://github.com/RisingStack/koa-prerender/pull/16

Replace your line 104 in index.js: if (query && query.hasOwnProperty('_escaped_fragment_')) { With this: if (query && query['_escaped_fragment_'] !== undefined) {

vdyachenko777 avatar Sep 25 '20 13:09 vdyachenko777