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

Fix TypeError: Object.keys called on non-object #176

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/util/urltils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ module.exports = {
parseParameters : function parseParameters(requestURL) {
var parsed = url.parse(requestURL, true)
, parameters = {}


if (parsed.search !== '') {

if (parsed.search) {
Object.keys(parsed.query).forEach(function cb_forEach(key) {
if (parsed.query[key] === '' && parsed.path.indexOf(key + '=') < 0) {
parameters[key] = true
Expand Down
18 changes: 16 additions & 2 deletions test/unit/urltils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var path = require('path')
, chai = require('chai')
, expect = chai.expect
, urltils = require('../../lib/util/urltils.js')


describe("NR URL utilities", function () {
describe("scrubbing URLs", function () {
Expand All @@ -13,6 +13,20 @@ describe("NR URL utilities", function () {
})
})

describe("parsing parameters", function () {
it("should find empty object of params in url lacking query", function () {
expect(urltils.parseParameters('/favicon.ico')).deep.equal({});
})

it("should find v param in url containing ?v with no value", function () {
expect(urltils.parseParameters('/status?v')).deep.equal({v:true});
})

it("should find v param with value in url containing ?v=1", function () {
expect(urltils.parseParameters('/status?v=1')).deep.equal({v:'1'});
})
})

describe("determining whether an HTTP status code is an error", function () {
var config = {error_collector : {ignore_status_codes : []}}

Expand Down Expand Up @@ -129,7 +143,7 @@ describe("NR URL utilities", function () {
var config
, source
, dest


beforeEach(function () {
config = {
Expand Down