showdir-href-encoding.js 864 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const test = require('tap').test;
  3. const ecstatic = require('../lib/ecstatic');
  4. const http = require('http');
  5. const request = require('request');
  6. const path = require('path');
  7. const root = `${__dirname}/public`;
  8. const baseDir = 'base';
  9. test('url encoding in href', (t) => {
  10. const port = Math.floor((Math.random() * ((1 << 16) - 1e4)) + 1e4);
  11. const uri = `http://localhost:${port}${path.join('/', baseDir, 'show-dir%24%24href_encoding%24%24')}`;
  12. const server = http.createServer(
  13. ecstatic({
  14. root,
  15. baseDir,
  16. showDir: true,
  17. autoIndex: false,
  18. })
  19. );
  20. server.listen(port, () => {
  21. request.get({
  22. uri,
  23. }, (err, res, body) => {
  24. t.match(body, /href="\/base\/show-dir%24%24href_encoding%24%24\/aname%2Baplus.txt"/, 'We found the right href');
  25. server.close();
  26. t.end();
  27. });
  28. });
  29. });