native-url.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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. var url = new URL('b?a=1&b=2&c=3', 'http://a');
  7. var searchParams = url.searchParams;
  8. var result = '';
  9. url.pathname = 'c%20d';
  10. searchParams.forEach(function (value, key) {
  11. searchParams['delete']('b');
  12. result += key + value;
  13. });
  14. return (IS_PURE && !url.toJSON)
  15. || !searchParams.sort
  16. || url.href !== 'http://a/c%20d?a=1&c=3'
  17. || searchParams.get('c') !== '3'
  18. || String(new URLSearchParams('?a=1')) !== 'a=1'
  19. || !searchParams[ITERATOR]
  20. // throws in Edge
  21. || new URL('https://a@b').username !== 'a'
  22. || new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b'
  23. // not punycoded in Edge
  24. || new URL('http://тест').host !== 'xn--e1aybc'
  25. // not escaped in Chrome 62-
  26. || new URL('http://a#б').hash !== '#%D0%B1'
  27. // fails in Chrome 66-
  28. || result !== 'a1c3'
  29. // throws in Safari
  30. || new URL('http://x', undefined).host !== 'x';
  31. });