Skip to content

Grammar: maddr overwrites the URI host and ttl is lost; ; and = in the user part are re-escaped #1132

Open

Description

@trackoor

Describe the bug
In Grammar.URIParse / URI.toString():

  1. Parsing a SIP URI with a maddr parameter overwrites uri.host with the maddr value, and a ttl URI parameter is dropped instead of being added to uri.parameters.
  2. Calling toString() on a parsed URI re-escapes ; and = in the user part to %3B and %3D.
  3. A fully qualified domain name with a trailing dot (sip:[email protected].) fails to parse (URIParse returns undefined).

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].'));
EOF

Expected behavior

  1. u.host is 'atlanta.com', u.parameters is { maddr: '239.255.255.1', ttl: 15 } (or '15'), and u.toString() is 'sip:[email protected];maddr=239.255.255.1;ttl=15'.
  2. v.user is 'alice;day=tuesday' and v.toString() is 'sip:alice;[email protected]' (; and = are in user-unreserved in RFC 3261 Section 25.1, and per Section 19.1.4 escaped and unescaped forms are only equivalent for characters outside the reserved set).
  3. Grammar.URIParse('sip:[email protected].') parses a URI with 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] and main at 922920b2657e05b50c74f985c69bd7b165d70e56)

Additional context
In src/grammar/pegjs/src/grammar.pegjs:

  • maddr_param = "maddr="i maddr: host reuses the host rule, whose action assigns options.data.host = text(), overwriting the URI's host before new URI(...) is constructed in SIP_URI.
  • ttl_param writes to options.data.params['ttl'] instead of options.data.uri_params['ttl'].
  • In hostname = ( domainlabel "." )* toplabel "." ?, greedy matching of ( domainlabel "." )* consumes the final label and trailing dot, leaving nothing to match toplabel.
  • In src/grammar/uri.ts, escapeUser only unescapes :, +, ?, / after encodeURIComponent, leaving the remaining user-unreserved characters (&, =, $, ,, ;) percent-encoded.

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions