Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
byoungdale committed Jun 29, 2023
1 parent e573d9f commit 0c301ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function parse(data, lazy) {
for (let i = 1; i < data.length; ++i) {
const r = data[i].match(/^([\S]*?)\s*:\s*([\s\S]*)$/);
if (!r) {
return;
continue;
}

const name = getHeaderName(r[1]) ;
Expand Down
26 changes: 21 additions & 5 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ var parser = require('..').parser ;
var parseUri = require('..').parser.parseUri ;
var debug = require('debug')('drachtio-sip') ;

var optionsMsg = 'OPTIONS sip:[email protected] SIP/2.0\r\n' +
'Via: SIP/2.0/UDP 192.241.212.6:56500;branch=nGTWdf.1124599842;rport;alias\r\n' +
'From: sip:[email protected]:56500;tag=71186921\r\n' +
'To: sip:[email protected]\r\n' +
'Call-ID: [email protected]\r\n' +
'CSeq: 1 OPTIONS\r\n' +
'Contact: sip:[email protected]:56500\r\n' +
'Content-Length: 0\r\n' +
'Max-Forwards: 20\r\n' +
'User-Agent: wFkdhplQ\r\n' +
'Accept: text/plain\r\n';

describe('Parser', function(){
it('should provide headers as string values', function(){
var msg = new SipMessage(examples('invite')) ;
Expand All @@ -14,7 +26,7 @@ describe('Parser', function(){
it('should optionally provide a parsed header', function(){
var msg = new SipMessage(examples('invite')) ;
var obj = msg.getParsedHeader('from') ;
obj.should.be.type('object');
obj.should.be.type('object');
obj.should.have.property('uri') ;
}) ;

Expand Down Expand Up @@ -102,24 +114,24 @@ describe('Parser', function(){
uri.family.should.eql('ipv6');
uri.host.should.eql('[2601:182:cd00:d4c6:604b:16f1:3f5a:44f8]') ;
uri.port.should.eql(61219);
}) ;
}) ;
it('should parse a sip uri with a dash or underscore', function(){
var uri = parseUri('sip:[email protected]') ;
uri.family.should.eql('ipv4');
uri.host.should.eql('cor10-san.sip.phone.com') ;
uri.user.should.eql('116751x0');
}) ;
}) ;
it('should parse a sips uri', function(){
var uri = parseUri('sips:[email protected]') ;
uri.family.should.eql('ipv4');
uri.host.should.eql('cor10-san.sip.phone.com') ;
uri.user.should.eql('116751x0');
uri.scheme.should.eql('sips');
}) ;
}) ;
it('should parse a multi-part header', function(){
var msg = new SipMessage(examples('siprec')) ;
msg.payload.length.should.eql(2);
}) ;
}) ;
it('should parse a multi-part header with whitespace before boundary', function(){
var msg = new SipMessage(examples('siprec2')) ;
msg.payload.length.should.eql(2);
Expand All @@ -139,5 +151,9 @@ describe('Parser', function(){
msg.get('From').should.eql('"Dave" <sip:daveh@localhost>;tag=1234') ;
msg.callingName.should.eql('Dave');
}) ;
it('should parse request with carriage return on last line', function(){
var msg = new SipMessage(optionsMsg) ;
(typeof msg.get('from')).should.eql('string') ;
}) ;
}) ;

0 comments on commit 0c301ed

Please sign in to comment.