native-url.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. var fails = require('../internals/fails');
  2. var wellKnownSymbol = require('../internals/well-known-symbol');
  3. var IS_PURE = require('../internals/is-pure');
  4. var ITERATOR = wellKnownSymbol('iterator');
  5. module.exports = !fails(function () {
  6. // eslint-disable-next-line unicorn/relative-url-style -- required for testing
  7. var url = new URL('b?a=1&b=2&c=3', 'http://a');
  8. var searchParams = url.searchParams;
  9. var result = '';
  10. url.pathname = 'c%20d';
  11. searchParams.forEach(function (value, key) {
  12. searchParams['delete']('b');
  13. result += key + value;
  14. });
  15. return (IS_PURE && !url.toJSON)
  16. || !searchParams.sort
  17. || url.href !== 'http://a/c%20d?a=1&c=3'
  18. || searchParams.get('c') !== '3'
  19. || String(new URLSearchParams('?a=1')) !== 'a=1'
  20. || !searchParams[ITERATOR]
  21. // throws in Edge
  22. || new URL('https://a@b').username !== 'a'
  23. || new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b'
  24. // not punycoded in Edge
  25. || new URL('http://тест').host !== 'xn--e1aybc'
  26. // not escaped in Chrome 62-
  27. || new URL('http://a#б').hash !== '#%D0%B1'
  28. // fails in Chrome 66-
  29. || result !== 'a1c3'
  30. // throws in Safari
  31. || new URL('http://x', undefined).host !== 'x';
  32. });