urn-full-input.test.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. const test = require('tape')
  3. const fastURI = require('..')
  4. test('URN parsing validates the complete scheme-specific input', (t) => {
  5. const embedded = fastURI.parse('urn:x|foo:bar')
  6. t.equal(embedded.error, 'URN can not be parsed.', 'does not search for a later nid:nss substring')
  7. t.equal(embedded.nid, undefined, 'does not adopt the later nid')
  8. t.equal(embedded.nss, undefined, 'does not adopt the later nss')
  9. const trailing = fastURI.parse('urn:foo:bar|ignored')
  10. t.equal(trailing.error, 'URN can not be parsed.', 'rejects trailing input outside the RFC 2141 NSS grammar')
  11. t.equal(trailing.nid, undefined, 'does not return an nid from a partial match')
  12. t.equal(trailing.nss, undefined, 'does not return a truncated nss')
  13. t.end()
  14. })
  15. test('URN parsing preserves the complete RFC 2141 NSS', (t) => {
  16. const parsed = fastURI.parse('urn:foo:allowed/evil')
  17. t.equal(parsed.error, undefined, 'accepts slash in an RFC 2141 NSS')
  18. t.equal(parsed.nid, 'foo', 'parses the nid')
  19. t.equal(parsed.nss, 'allowed/evil', 'preserves the complete NSS')
  20. t.equal(fastURI.normalize('urn:foo:allowed/evil'), 'urn:foo:allowed/evil', 'normalization retains slash data')
  21. t.equal(fastURI.equal('urn:foo:allowed/evil', 'urn:foo:allowed'), false, 'distinct NSS values do not compare equal')
  22. t.end()
  23. })