SIP.js icon indicating copy to clipboard operation
SIP.js copied to clipboard

UA configuration option `uri` requires double-encoding

Open markandrus opened this issue 10 years ago • 2 comments

I haven't had a chance to dig into the code, but here is what I observe: I would like to register as user ann% at xyz.com, so I construct the URI ann%[email protected] and call

new SIP.UA({
  // some options elided
  uri: 'ann%[email protected]',
  // some options elided
});

but this causes SIP.js to throw an Uncaught URIError: URI malformed before even attempting to register. The issue is that Utils.escapeUser is being passed ann% instead of ann%25, and calling decodeURIComponent on ann% throws the error.

A workaround is to double-encode the URI. For example, the following works

new SIP.UA({
  // some options elided
  uri: 'ann%[email protected]',
  // some options elided
});

and results in a successful registration

REGISTER sip:xyz.com SIP/2.0
Via: SIP/2.0/WSS fdcmr7jactla.invalid;branch=z9hG4bK7237196
Max-Forwards: 70
To: <sip:ann%[email protected]>
From: <sip:ann%[email protected]>;tag=dgcrgt5rd1
Call-ID: 39fl7u84ap63b42sh62f8t
CSeq: 82 REGISTER
Contact: <sip:[email protected];transport=wss>;reg-id=1;+sip.instance="<urn:uuid:6686f39a-9f61-4072-809b-b7a9dab96ba1>";expires=600
Allow: ACK,CANCEL,INVITE,MESSAGE,BYE,OPTIONS,INFO,NOTIFY
Supported: path, gruu, outbound
User-Agent: SIP.js/0.7.3
Content-Length: 0

markandrus avatar Feb 03 '16 23:02 markandrus

This is an issue with the URI class. The new API requires a URI instance be passed as an options, so that's indirectly no longer an issue. But the URI class should not be implemented in a fashion where toString() depends on decodeURIComponent which can (and does) throw URIError: URI malformed.

The short is the URI class needs to be modified and this is also somewhat related to how the parser utilizes URI. Adding it to my TODO list (towards the bottom).

john-e-riordan avatar Sep 17 '19 17:09 john-e-riordan

Related to #791

john-e-riordan avatar May 10 '20 13:05 john-e-riordan