Permalink
Browse files

Disallow null/undefined endpoint arguments

  • Loading branch information...
lsegal committed Mar 12, 2013
1 parent 8665890 commit 937229e90c46c63f2775b8fcd20ac6ae47b38a28
Showing with 7 additions and 1 deletion.
  1. +3 −1 lib/http.js
  2. +4 −0 test/endpoint.spec.coffee
View
@@ -57,7 +57,9 @@ AWS.Endpoint = inherit({
* @param endpoint [String] the URL to construct an endpoint from
*/
constructor: function Endpoint(endpoint, config) {
- if (typeof endpoint !== 'string') {
+ if (typeof endpoint === 'undefined' || endpoint === null) {
+ throw new Error('Invalid endpoint: ' + endpoint);
+ } else if (typeof endpoint !== 'string') {
return AWS.util.copy(endpoint);
}
@@ -14,6 +14,10 @@
AWS = require('../lib/core')
describe 'AWS.Endpoint', ->
+ it 'throws error if parameter is null/undefined', ->
+ expect(-> new AWS.Endpoint(null)).toThrow('Invalid endpoint: null')
+ expect(-> new AWS.Endpoint(undefined)).toThrow('Invalid endpoint: undefined')
+
it 'copy constructs Endpoint', ->
origEndpoint = new AWS.Endpoint('http://domain.com')
endpoint = new AWS.Endpoint(origEndpoint)

0 comments on commit 937229e

Please sign in to comment.