debian-mirror-gitlab/core-js/internals/native-url.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-09-25 13:30:05 +05:30
var fails = require('../internals/fails');
var wellKnownSymbol = require('../internals/well-known-symbol');
var IS_PURE = require('../internals/is-pure');
var ITERATOR = wellKnownSymbol('iterator');
module.exports = !fails(function () {
2019-10-31 01:37:42 +05:30
var url = new URL('b?a=1&b=2&c=3', 'http://a');
2019-09-25 13:30:05 +05:30
var searchParams = url.searchParams;
2019-10-31 01:37:42 +05:30
var result = '';
2019-09-25 13:30:05 +05:30
url.pathname = 'c%20d';
2019-10-31 01:37:42 +05:30
searchParams.forEach(function (value, key) {
searchParams['delete']('b');
result += key + value;
});
2019-09-25 13:30:05 +05:30
return (IS_PURE && !url.toJSON)
|| !searchParams.sort
2019-10-31 01:37:42 +05:30
|| url.href !== 'http://a/c%20d?a=1&c=3'
|| searchParams.get('c') !== '3'
2019-09-25 13:30:05 +05:30
|| String(new URLSearchParams('?a=1')) !== 'a=1'
|| !searchParams[ITERATOR]
// throws in Edge
|| new URL('https://a@b').username !== 'a'
|| new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b'
// not punycoded in Edge
|| new URL('http://тест').host !== 'xn--e1aybc'
// not escaped in Chrome 62-
2019-10-31 01:37:42 +05:30
|| new URL('http://a#б').hash !== '#%D0%B1'
// fails in Chrome 66-
|| result !== 'a1c3'
// throws in Safari
|| new URL('http://x', undefined).host !== 'x';
2019-09-25 13:30:05 +05:30
});