11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst qs = require('querystring'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciassert.strictEqual(qs.escape(5), '5'); 81cb0ef41Sopenharmony_ciassert.strictEqual(qs.escape('test'), 'test'); 91cb0ef41Sopenharmony_ciassert.strictEqual(qs.escape({}), '%5Bobject%20Object%5D'); 101cb0ef41Sopenharmony_ciassert.strictEqual(qs.escape([5, 10]), '5%2C10'); 111cb0ef41Sopenharmony_ciassert.strictEqual(qs.escape('Ŋōđĕ'), '%C5%8A%C5%8D%C4%91%C4%95'); 121cb0ef41Sopenharmony_ciassert.strictEqual(qs.escape('testŊōđĕ'), 'test%C5%8A%C5%8D%C4%91%C4%95'); 131cb0ef41Sopenharmony_ciassert.strictEqual(qs.escape(`${String.fromCharCode(0xD800 + 1)}test`), 141cb0ef41Sopenharmony_ci '%F0%90%91%B4est'); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciassert.throws( 171cb0ef41Sopenharmony_ci () => qs.escape(String.fromCharCode(0xD800 + 1)), 181cb0ef41Sopenharmony_ci { 191cb0ef41Sopenharmony_ci code: 'ERR_INVALID_URI', 201cb0ef41Sopenharmony_ci name: 'URIError', 211cb0ef41Sopenharmony_ci message: 'URI malformed' 221cb0ef41Sopenharmony_ci } 231cb0ef41Sopenharmony_ci); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci// Using toString for objects 261cb0ef41Sopenharmony_ciassert.strictEqual( 271cb0ef41Sopenharmony_ci qs.escape({ test: 5, toString: () => 'test', valueOf: () => 10 }), 281cb0ef41Sopenharmony_ci 'test' 291cb0ef41Sopenharmony_ci); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci// `toString` is not callable, must throw an error. 321cb0ef41Sopenharmony_ci// Error message will vary between different JavaScript engines, so only check 331cb0ef41Sopenharmony_ci// that it is a `TypeError`. 341cb0ef41Sopenharmony_ciassert.throws(() => qs.escape({ toString: 5 }), TypeError); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci// Should use valueOf instead of non-callable toString. 371cb0ef41Sopenharmony_ciassert.strictEqual(qs.escape({ toString: 5, valueOf: () => 'test' }), 'test'); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci// Error message will vary between different JavaScript engines, so only check 401cb0ef41Sopenharmony_ci// that it is a `TypeError`. 411cb0ef41Sopenharmony_ciassert.throws(() => qs.escape(Symbol('test')), TypeError); 42