Skip to content

Commit

Permalink
Fixed schemes with custom components not resolving correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
garycourt committed Apr 11, 2018
1 parent 29fdbec commit e75c90b
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 17 deletions.
14 changes: 12 additions & 2 deletions dist/es5/uri.all.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/es5/uri.all.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/es5/uri.all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/es5/uri.all.min.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/esnext/uri.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/esnext/uri.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/esnext/util.d.ts
Expand Up @@ -3,3 +3,4 @@ export declare function subexp(str: string): string;
export declare function typeOf(o: any): string;
export declare function toUpperCase(str: string): string;
export declare function toArray(obj: any): Array<any>;
export declare function assign(target: object, source: any): any;
9 changes: 9 additions & 0 deletions dist/esnext/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/esnext/util.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "uri-js",
"version": "4.2.0",
"version": "4.2.1",
"description": "An RFC 3986/3987 compliant, scheme extendable URI/IRI parsing/validating/resolving library for JavaScript.",
"main": "dist/es5/uri.all.js",
"types": "dist/es5/uri.all.d.ts",
Expand Down Expand Up @@ -48,9 +48,9 @@
},
"homepage": "https://github.com/garycourt/uri-js",
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-cli": "^6.26.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-latest": "^6.24.0",
"babel-preset-latest": "^6.24.1",
"mocha": "^3.2.0",
"mocha-qunit-ui": "^0.1.3",
"rollup": "^0.41.6",
Expand Down
5 changes: 3 additions & 2 deletions src/uri.ts
Expand Up @@ -37,7 +37,7 @@
import URI_PROTOCOL from "./regexps-uri";
import IRI_PROTOCOL from "./regexps-iri";
import punycode from "punycode";
import { toUpperCase, typeOf } from "./util";
import { toUpperCase, typeOf, assign } from "./util";

export interface URIComponents {
scheme?:string;
Expand Down Expand Up @@ -513,7 +513,8 @@ export function resolveComponents(base:URIComponents, relative:URIComponents, op
};

export function resolve(baseURI:string, relativeURI:string, options?:URIOptions):string {
return serialize(resolveComponents(parse(baseURI, options), parse(relativeURI, options), options, true), options);
const schemelessOptions = assign({ scheme : 'null' }, options);
return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
};

export function normalize(uri:string, options?:URIOptions):string;
Expand Down
11 changes: 11 additions & 0 deletions src/util.ts
Expand Up @@ -27,3 +27,14 @@ export function toUpperCase(str:string):string {
export function toArray(obj:any):Array<any> {
return obj !== undefined && obj !== null ? (obj instanceof Array ? obj : (typeof obj.length !== "number" || obj.split || obj.setInterval || obj.call ? [obj] : Array.prototype.slice.call(obj))) : [];
}


export function assign(target: object, source: any): any {
const obj = target as any;
if (source) {
for (const key in source) {
obj[key] = source[key];
}
}
return obj;
}
8 changes: 8 additions & 0 deletions tests/tests.js
Expand Up @@ -567,6 +567,14 @@ if (URI.SCHEMES["urn"]) {
strictEqual(URI.equal("urn:foo:a123%2C456", "URN:FOO:a123%2c456"), true);
});

test("URN Resolving", function () {
//example from epoberezkin
strictEqual(URI.resolve('', 'urn:some:ip:prop'), 'urn:some:ip:prop');
strictEqual(URI.resolve('#', 'urn:some:ip:prop'), 'urn:some:ip:prop');
strictEqual(URI.resolve('urn:some:ip:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop');
strictEqual(URI.resolve('urn:some:other:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop');
});

//
// URN UUID
//
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Expand Up @@ -89,7 +89,7 @@ aws4@^1.2.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"

babel-cli@^6.24.0:
babel-cli@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-cli/-/babel-cli-6.26.0.tgz#502ab54874d7db88ad00b887a06383ce03d002f1"
dependencies:
Expand Down Expand Up @@ -533,7 +533,7 @@ babel-preset-es2017@^6.24.1:
babel-plugin-syntax-trailing-function-commas "^6.22.0"
babel-plugin-transform-async-to-generator "^6.24.1"

babel-preset-latest@^6.24.0:
babel-preset-latest@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-preset-latest/-/babel-preset-latest-6.24.1.tgz#677de069154a7485c2d25c577c02f624b85b85e8"
dependencies:
Expand Down

0 comments on commit e75c90b

Please sign in to comment.