Skip to content

Commit e385840

Browse files
committed
Make JsSIP.URI and JsSIP.NameAddrHeader more robust.
1 parent b0603e3 commit e385840

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/NameAddrHeader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ JsSIP.NameAddrHeader.prototype = {
4848

4949
hasParam: function(key) {
5050
if(key) {
51-
return this.parameters.hasOwnProperty(key.toLowerCase()) && true || false;
51+
return (this.parameters.hasOwnProperty(key.toLowerCase()) && true) || false;
5252
}
5353
},
5454

@@ -81,7 +81,7 @@ JsSIP.NameAddrHeader.prototype = {
8181

8282
for (parameter in this.parameters) {
8383
body += ';' + parameter;
84-
body += (this.parameters[parameter] === null)? '' : '=' + this.parameters[parameter];
84+
body += (this.parameters[parameter] === null) ? '' : '=' + this.parameters[parameter];
8585
}
8686

8787
return body;

src/URI.js

+12-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ JsSIP.URI = function(scheme, user, host, port, parameters, headers) {
1818
throw new TypeError('missing or invalid "host" parameter');
1919
}
2020

21+
this.scheme = scheme || JsSIP.C.SIP;
22+
2123
// Initialize parameters
2224
this.parameters = {};
2325
this.headers = {};
@@ -62,7 +64,7 @@ JsSIP.URI = function(scheme, user, host, port, parameters, headers) {
6264
JsSIP.URI.prototype = {
6365
setParam: function(key, value) {
6466
if(key) {
65-
this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null)? null : value.toString().toLowerCase();
67+
this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null) ? null : value.toString().toLowerCase();
6668
}
6769
},
6870

@@ -74,7 +76,7 @@ JsSIP.URI.prototype = {
7476

7577
hasParam: function(key) {
7678
if(key) {
77-
return this.parameters.hasOwnProperty(key.toLowerCase()) && true || false;
79+
return (this.parameters.hasOwnProperty(key.toLowerCase()) && true) || false;
7880
}
7981
},
8082

@@ -104,7 +106,7 @@ JsSIP.URI.prototype = {
104106

105107
hasHeader: function(name) {
106108
if(name) {
107-
return this.headers.hasOwnProperty(name.toLowerCase()) && true || false;
109+
return (this.headers.hasOwnProperty(name.toLowerCase()) && true) || false;
108110
}
109111
},
110112

@@ -133,24 +135,17 @@ JsSIP.URI.prototype = {
133135
},
134136

135137
toString: function(){
136-
var header, parameter, idx,
137-
headers = [],
138-
uri = '';
139-
140-
if(!this.host) {
141-
console.error(JsSIP.C.LOG_URI +'cannot print a SIP URI without host');
142-
throw new TypeError('cannot print a SIP URI without host');
143-
}
138+
var header, parameter, idx, uri,
139+
headers = [];
144140

145-
uri = this.scheme || JsSIP.C.SIP;
146-
uri += ':';
141+
uri = this.scheme + ':';
147142
uri += this.user ? JsSIP.Utils.escapeUser(this.user) + '@' : '';
148143
uri += this.host;
149144
uri += this.port ? ':' + this.port : '';
150145

151146
for (parameter in this.parameters) {
152-
uri += ';'+ parameter.toLowerCase();
153-
uri += (this.parameters[parameter] === null )? '' : '=' + this.parameters[parameter];
147+
uri += ';'+ parameter;
148+
uri += (this.parameters[parameter] === null) ? '' : '=' + this.parameters[parameter];
154149
}
155150

156151
for(header in this.headers) {
@@ -166,10 +161,9 @@ JsSIP.URI.prototype = {
166161
return uri;
167162
},
168163
toAor: function(){
169-
var aor = '';
164+
var aor;
170165

171-
aor += this.scheme || JsSIP.C.SIP;
172-
aor += ':';
166+
aor = this.scheme + ':';
173167
aor += this.user ? JsSIP.Utils.escapeUser(this.user) + '@' : '';
174168
aor += this.host;
175169

0 commit comments

Comments
 (0)