Repository navigation
Open
Description
Describe the bug
In Grammar.URIParse / URI.toString():
- Parsing a SIP URI with a
maddrparameter overwritesuri.hostwith themaddrvalue, and attlURI parameter is dropped instead of being added touri.parameters. - Calling
toString()on a parsed URI re-escapes;and=in the user part to%3Band%3D. - A fully qualified domain name with a trailing dot (
sip:[email protected].) fails to parse (URIParsereturnsundefined).
Logs
Not applicable (reproducible directly via Grammar.URIParse).
To Reproduce (if possible)
Both URI examples below are taken from RFC 3261 Section 19.1.3:
npm i [email protected]
node --input-type=module <<'EOF'
import { Grammar } from 'sip.js';
const u = Grammar.URIParse('sip:[email protected];maddr=239.255.255.1;ttl=15');
console.log(u.host, u.parameters, u.toString());
const v = Grammar.URIParse('sip:alice;[email protected]');
console.log(v.user, v.toString());
console.log(Grammar.URIParse('sip:[email protected].'));
EOFExpected behavior
u.hostis'atlanta.com',u.parametersis{ maddr: '239.255.255.1', ttl: 15 }(or'15'), andu.toString()is'sip:[email protected];maddr=239.255.255.1;ttl=15'.v.useris'alice;day=tuesday'andv.toString()is'sip:alice;[email protected]'(;and=are inuser-unreservedin RFC 3261 Section 25.1, and per Section 19.1.4 escaped and unescaped forms are only equivalent for characters outside thereservedset).Grammar.URIParse('sip:[email protected].')parses aURIwith host'atlanta.com.'(hostname = *( domainlabel "." ) toplabel [ "." ]).
Observed behavior
239.255.255.1 { maddr: '239.255.255.1' } sip:[email protected];maddr=239.255.255.1
alice;day=tuesday sip:alice%3Bday%[email protected]
undefined
Environment Information
- Backend Server and version: Node.js v26.13.0
- Browser and version: N/A (
[email protected]andmainat922920b2657e05b50c74f985c69bd7b165d70e56)
Additional context
In src/grammar/pegjs/src/grammar.pegjs:
maddr_param = "maddr="i maddr: hostreuses thehostrule, whose action assignsoptions.data.host = text(), overwriting the URI's host beforenew URI(...)is constructed inSIP_URI.ttl_paramwrites tooptions.data.params['ttl']instead ofoptions.data.uri_params['ttl'].- In
hostname = ( domainlabel "." )* toplabel "." ?, greedy matching of( domainlabel "." )*consumes the final label and trailing dot, leaving nothing to matchtoplabel. - In
src/grammar/uri.ts,escapeUseronly unescapes:,+,?,/afterencodeURIComponent, leaving the remaininguser-unreservedcharacters (&,=,$,,,;) percent-encoded.
Credit: https://ucsbplse.github.io/
Metadata
Metadata
Assignees
Labels
No labels
Activity