rfc-3986.test.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict'
  2. const test = require('tape')
  3. const fastURI = require('..')
  4. test('RFC 3986', (t) => {
  5. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/', secure: true }),
  6. 'http://example.com/', 'http://example.com/')
  7. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/foo', secure: true }),
  8. 'http://example.com/foo', 'http://example.com/foo')
  9. // A. If the input buffer begins with a prefix of "../" or "./",
  10. // then remove that prefix from the input buffer; otherwise,
  11. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '../', secure: true }),
  12. 'http://example.com/', 'http://example.com/')
  13. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: './', secure: true }),
  14. 'http://example.com/', 'http://example.com/')
  15. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '../../', secure: true }),
  16. 'http://example.com/', 'http://example.com/')
  17. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '././', secure: true }),
  18. 'http://example.com/', 'http://example.com/')
  19. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: './../', secure: true }),
  20. 'http://example.com/', 'http://example.com/')
  21. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '.././', secure: true }),
  22. 'http://example.com/', 'http://example.com/')
  23. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '../foo', secure: true }),
  24. 'http://example.com/foo', 'http://example.com/foo')
  25. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: './foo', secure: true }),
  26. 'http://example.com/foo', 'http://example.com/foo')
  27. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '../../foo', secure: true }),
  28. 'http://example.com/foo', 'http://example.com/foo')
  29. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '././foo', secure: true }),
  30. 'http://example.com/foo', 'http://example.com/foo')
  31. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: './../foo', secure: true }),
  32. 'http://example.com/foo', 'http://example.com/foo')
  33. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '.././foo', secure: true }),
  34. 'http://example.com/foo', 'http://example.com/foo')
  35. // B. if the input buffer begins with a prefix of "/./" or "/.",
  36. // where "." is a complete path segment, then replace that
  37. // prefix with "/" in the input buffer; otherwise,
  38. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/./', secure: true }),
  39. 'http://example.com/', 'http://example.com/')
  40. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/.', secure: true }),
  41. 'http://example.com/', 'http://example.com/')
  42. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/./foo', secure: true }),
  43. 'http://example.com/foo', 'http://example.com/foo')
  44. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/.././foo', secure: true }),
  45. 'http://example.com/foo', 'http://example.com/foo')
  46. // C. if the input buffer begins with a prefix of "/../" or "/..",
  47. // where ".." is a complete path segment, then replace that
  48. // prefix with "/" in the input buffer and remove the last
  49. // segment and its preceding "/" (if any) from the output
  50. // buffer; otherwise,
  51. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/../', secure: true }),
  52. 'http://example.com/', 'http://example.com/')
  53. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/..', secure: true }),
  54. 'http://example.com/', 'http://example.com/')
  55. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/../foo', secure: true }),
  56. 'http://example.com/foo', 'http://example.com/foo')
  57. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/foo/..', secure: true }),
  58. 'http://example.com/', 'http://example.com/')
  59. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/foo/bar/..', secure: true }),
  60. 'http://example.com/foo/', 'http://example.com/foo/')
  61. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/foo/../bar/..', secure: true }),
  62. 'http://example.com/', 'http://example.com/')
  63. // D. if the input buffer consists only of "." or "..", then remove
  64. // that from the input buffer; otherwise,
  65. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/.', secure: true }),
  66. 'http://example.com/', 'http://example.com/')
  67. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '/..', secure: true }),
  68. 'http://example.com/', 'http://example.com/')
  69. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '.', secure: true }),
  70. 'http://example.com/', 'http://example.com/')
  71. t.strictEqual(fastURI.serialize({ scheme: 'http', host: 'example.com', path: '..', secure: true }),
  72. 'http://example.com/', 'http://example.com/')
  73. t.end()
  74. })