How to use the url.resolveObject function in url

To help you get started, we’ve selected a few url examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graalvm / graaljs / test / parallel / test-url-relative.js View on Github external
'use strict';
require('../common');
const assert = require('assert');
const inspect = require('util').inspect;
const url = require('url');

// When source is false
assert.strictEqual(url.resolveObject('', 'foo'), 'foo');

/*
 [from, path, expected]
*/
const relativeTests = [
  ['/foo/bar/baz', 'quux', '/foo/bar/quux'],
  ['/foo/bar/baz', 'quux/asdf', '/foo/bar/quux/asdf'],
  ['/foo/bar/baz', 'quux/baz', '/foo/bar/quux/baz'],
  ['/foo/bar/baz', '../quux/baz', '/foo/quux/baz'],
  ['/foo/bar/baz', '/bar', '/bar'],
  ['/foo/bar/baz/', 'quux', '/foo/bar/baz/quux'],
  ['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
  ['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],
  ['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],
  ['/foo', '.', '/'],
  ['/foo', '..', '/'],
github teknopaul / nodetoy / server / server / router.js View on Github external
route = function(request, response, chain) {
	try {
		
		var url = parse(request.url, true);
		url = resolveObject(url, url); // strange syntax (url passed twice) but this resolves ../../ paths in the URL
		url = parse(request.url, true);
		
		if (url.pathname.indexOf('/data/') == 0) {
			service(restModule, request, response, url);
		}
		else if (url.pathname.indexOf('/app/') == 0) {
			service(appModule, request, response, url);
		}
		else if (url.pathname.indexOf('/favicon.png') == 0 ||  url.pathname.indexOf('/favicon.ico') == 0) {
			service(faviconModule, request, response, url);
		}
		else if (url.pathname.indexOf('/config/') == 0) {
			service(configModule, request, response, url);
		}
		else if (request.method == 'GET') {
			defaults.fileNotFound(response);
github alexgorbatchev / node-browser-builtins / test / browser / url-simple.js View on Github external
relativeTests.forEach(function(relativeTest) {
    var actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]),
        expected = url.parse(relativeTest[2]);


    t.deepEqual(objectify(actual), objectify(expected));

    expected = relativeTest[2];
    actual = url.format(actual);

    t.equal(actual, expected,
                 'format(' + actual + ') == ' + expected + '\nactual:' + actual);
  });
github graalvm / graaljs / test / parallel / test-url.js View on Github external
relativeTests2.forEach(function(relativeTest) {
  var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]),
      expected = url.parse(relativeTest[2]);

  assert.deepEqual(actual, expected);

  var expected = relativeTest[2],
      actual = url.format(actual);

  assert.equal(actual, expected,
               'format(' + relativeTest[1] + ') == ' + expected +
               '\nactual:' + actual);
});
github graalvm / graaljs / test / parallel / test-url-relative.js View on Github external
relativeTests.forEach(function(relativeTest) {
  let actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]);
  let expected = url.parse(relativeTest[2]);


  assert.deepStrictEqual(actual, expected);

  expected = relativeTest[2];
  actual = url.format(actual);

  assert.strictEqual(actual, expected,
                     `format(${actual}) == ${expected}\n` +
                     `actual: ${actual}`);
});
github webpack / node-libs-browser / test / suite / node / simple / test-url.js View on Github external
relativeTests2.forEach(function(relativeTest) {
  var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]),
      expected = url.parse(relativeTest[2]);

  //because of evaluation order
  //resolveObject(parse(x), y) == parse(resolve(x, y)) will differ by
  //false-ish values.  remove all except host and hostname
  for (var i in actual) {
    if (actual[i] === undefined ||
        (!emptyIsImportant.hasOwnProperty(i) && !actual[i])) {
      delete actual[i];
    }
  }

  assert.deepEqual(actual, expected);

  var expected = relativeTest[2],
      actual = url.format(actual);
github graalvm / graaljs / test / parallel / test-url-relative.js View on Github external
relativeTests2.forEach(function(relativeTest) {
  let actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]);
  let expected = url.parse(relativeTest[2]);

  assert.deepStrictEqual(
    actual,
    expected,
    `expected ${inspect(expected)} but got ${inspect(actual)}`
  );

  expected = url.format(relativeTest[2]);
  actual = url.format(actual);

  assert.strictEqual(actual, expected,
                     `format(${relativeTest[1]}) == ${expected}\n` +
                     `actual: ${actual}`);
});