ipv6-canonical.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict'
  2. const test = require('tape')
  3. const fastURI = require('..')
  4. test('IPv6 hosts normalize to the RFC 5952 canonical form', (t) => {
  5. const cases = [
  6. ['http://[0:0:0:0:0:0:0:1]/', 'http://[::1]/'],
  7. ['http://[0:0:0:0:0:0:0:0]/', 'http://[::]/'],
  8. ['http://[2001:0db8:0000:0000:0000:0000:0000:0001]/', 'http://[2001:db8::1]/'],
  9. ['http://[2001:0:0:0:0:0:0:1]/', 'http://[2001::1]/'],
  10. ['http://[fe80:0:0:0:0:0:0:1]/', 'http://[fe80::1]/'],
  11. ['http://[1:0:0:0:2:0:0:3]/', 'http://[1::2:0:0:3]/']
  12. ]
  13. for (const [uri, normalized] of cases) {
  14. t.equal(fastURI.normalize(uri), normalized, `${uri} normalizes to ${normalized}`)
  15. }
  16. t.end()
  17. })
  18. test('IPv6 equal() matches the same address across compressed and expanded forms', (t) => {
  19. const pairs = [
  20. ['http://[::1]/', 'http://[0:0:0:0:0:0:0:1]/'],
  21. ['http://[::]/', 'http://[0:0:0:0:0:0:0:0]/'],
  22. ['http://[2001:db8::1]/', 'http://[2001:0db8:0000:0000:0000:0000:0000:0001]/'],
  23. ['http://[1::2:0:0:3]/', 'http://[1:0:0:0:2:0:0:3]/']
  24. ]
  25. for (const [a, b] of pairs) {
  26. t.equal(fastURI.equal(a, b), true, `${a} equals ${b}`)
  27. }
  28. t.end()
  29. })