From ec3d57bb71cf4d72ff94751989ec8390f08f3316 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Aste Kompen Date: Sat, 10 Feb 2018 11:45:58 -0300 Subject: [PATCH 1/2] fix(core): properly parse query property (#367) closes #366 --- src/URI.js | 4 ++++ test/test.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/URI.js b/src/URI.js index 1d7957a0..d2cf26d6 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1241,10 +1241,14 @@ } else if (_URI || _object) { var src = _URI ? href._parts : href; for (key in src) { + if (key === 'query') { continue; } if (hasOwn.call(this._parts, key)) { this._parts[key] = src[key]; } } + if (src.query) { + this.query(src.query, false); + } } else { throw new TypeError('invalid input'); } diff --git a/test/test.js b/test/test.js index fe62c01c..c29c2ad1 100644 --- a/test/test.js +++ b/test/test.js @@ -34,6 +34,49 @@ ok(u instanceof URI, 'instanceof URI'); ok(u._parts.hostname !== undefined, 'host undefined'); }); + + test('new URI(object)', function() { + var u = new URI({ + protocol: 'http', + hostname: 'example.org', + query: { + foo: 'bar', + bar: 'foo', + }, + }); + ok(u instanceof URI, 'instanceof URI'); + ok(typeof u.query() === 'string', 'query is string'); + equal(u.query(), 'foo=bar&bar=foo', 'query has right value'); + equal(u.search(), '?foo=bar&bar=foo', 'search has right value'); + deepEqual(u.query(true), { foo: 'bar', bar: 'foo' }, 'query(true) value'); + deepEqual(u.search(true), { foo: 'bar', bar: 'foo' }, 'search(true) value'); + }); + test('new URI(object)', function() { + var u = new URI({ + protocol: 'http', + hostname: 'example.org', + query: 'foo=bar&bar=foo', + }); + ok(u instanceof URI, 'instanceof URI'); + ok(typeof u.query() === 'string', 'query is string'); + equal(u.query(), 'foo=bar&bar=foo', 'query has right value'); + equal(u.search(), '?foo=bar&bar=foo', 'search has right value'); + deepEqual(u.query(true), { foo: 'bar', bar: 'foo' }, 'query(true) value'); + deepEqual(u.search(true), { foo: 'bar', bar: 'foo' }, 'search(true) value'); + }); + test('new URI(object)', function() { + var u = new URI({ + protocol: 'http', + hostname: 'example.org', + query: '?foo=bar&bar=foo', + }); + ok(u instanceof URI, 'instanceof URI'); + ok(typeof u.query() === 'string', 'query is string'); + equal(u.query(), 'foo=bar&bar=foo', 'query has right value'); + equal(u.search(), '?foo=bar&bar=foo', 'search has right value'); + deepEqual(u.query(true), { foo: 'bar', bar: 'foo' }, 'query(true) value'); + deepEqual(u.search(true), { foo: 'bar', bar: 'foo' }, 'search(true) value'); + }); test('new URI(Location)', function () { var u = new URI(location); equal(u.href(), String(location.href), 'location object'); From fa46615b9934217a971edd482b59b9f88303db00 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sat, 10 Feb 2018 16:33:18 +0100 Subject: [PATCH 2/2] chore(build): bumping to version 1.19.1 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- build.js | 18 ++++++++-------- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URI.min.js | 44 +++++++++++++++++++-------------------- src/URITemplate.js | 2 +- src/jquery.URI.js | 28 ++++++++++++------------- src/jquery.URI.min.js | 2 +- 11 files changed, 57 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a90344a..e3641caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.19.1 (February 10th 2018) ### + +* fixing [`.href()`](http://medialize.github.io/URI.js/docs.html#href) to parse `query` property - [Issue #366](https://github.com/medialize/URI.js/issues/366), [PR #367](https://github.com/medialize/URI.js/issues/367) + ### 1.19.0 (October 1st 2017) ### * adding `.setFragment()` to [query fragment plugin](http://medialize.github.io/URI.js/docs.html#fragment-abuse-query) - [Issue #338](https://github.com/medialize/URI.js/issues/338), [PR #356](https://github.com/medialize/URI.js/issues/356) diff --git a/bower.json b/bower.json index 5a4b37dd..a043b31a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.0", + "version": "1.19.1", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index c17a8d31..df195827 100644 --- a/build.js +++ b/build.js @@ -1,17 +1,17 @@ (function($, undefined){ window.URL = window.webkitURL || window.URL; window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder; - + function build(files) { var $out = $('#output'), $progress = $('#prog'), sources = [], connections = [], source; - + $out.parent().hide(); $progress.show().prop('value', 1).text('Loading Files'); - + for (var i = 0, length = files.length; i < length; i++) { sources.push(""); (function(i, file){ @@ -20,7 +20,7 @@ function build(files) { }, "text")); })(i, files[i]); } - + $.when.apply($, connections).done(function() { $progress.prop('value', 2).text('Compiling Scripts'); $.post('https://closure-compiler.appspot.com/compile', { @@ -29,13 +29,13 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.19.0 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.19.1 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); $out.prev().prepend(download(code)); - }).error(function() { - alert("Your browser is incapable of cross-domain communication.\nPlease see instructions for manual build below."); + }).error(function() { + alert("Your browser is incapable of cross-domain communication.\nPlease see instructions for manual build below."); }); }); }; @@ -48,7 +48,7 @@ function download(code) { a.href = window.URL.createObjectURL(blob); a.textContent = 'Download'; a.dataset.downloadurl = ['text/javascript', a.download, a.href].join(':'); - + return a; }; @@ -70,7 +70,7 @@ $(function(){ var val = $(this).val(); val.length && files.push(val); }); - + build(files); }); }); diff --git a/package.json b/package.json index 2998baee..fdd0829f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.0", + "version": "1.19.1", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 5f389450..9aa9e9c5 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.19.0 + * Version: 1.19.1 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index e926a05b..2396a15b 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.19.0 + * Version: 1.19.1 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index d2cf26d6..cb52699e 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.19.0 + * Version: 1.19.1 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -81,7 +81,7 @@ return /^[0-9]+$/.test(value); } - URI.version = '1.19.0'; + URI.version = '1.19.1'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URI.min.js b/src/URI.min.js index 5386babf..75c8a4c7 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.19.0 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.19.1 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(f,n){"object"===typeof module&&module.exports?module.exports=n():"function"===typeof define&&define.amd?define(n):f.IPv6=n(f)})(this,function(f){var n=f&&f.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var k=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[k-1]&&""===h[k-2]&&h.pop();k=h.length;-1!==h[k-1].indexOf(".")&&(b=7);var q;for(q=0;qf;f++)if("0"===k[0]&&1f&&(k=g,f=n)):"0"===h[q]&&(p=!0,g=q,n=1);n>f&&(k=g,f=n);1=k||k>=b-1)return null;var n=h.list[f.slice(b+1)];return!n||0>n.indexOf(" " (function(f,n){"object"===typeof module&&module.exports?module.exports=n(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],n):f.URI=n(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,n,h,k){function b(a,c){var d=1<=arguments.length,l=2<=arguments.length;if(!(this instanceof b))return d?l?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var m=0;for(b=c.length;m]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", @@ -51,26 +51,26 @@ l.lastIndex=k+h.length))}l.lastIndex=0;return a};b.ensureValidHostname=function( }};b.ensureValidPort=function(a){if(a){var c=Number(a);if(!(/^[0-9]+$/.test(c)&&0c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&&(a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()), a;k.URI===this&&(k.URI=w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username=r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b= this.query(a,c);return"string"===typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn?a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString(); -this._string="";this._parts=b._parts();var l=a instanceof b,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=b.getDomAttribute(a),a=a[e]||"",e=!1);!l&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(l||e)for(d in l=l?a._parts:a,l)t.call(this._parts,d)&&(this._parts[d]=l[d]);else throw new TypeError("invalid input");this.build(!c);return this};e.is=function(a){var c=!1,d=!1,e=!1,m=!1,g=!1, -f=!1,k=!1,p=!this._parts.urn;this._parts.hostname&&(p=!1,d=b.ip4_expression.test(this._parts.hostname),e=b.ip6_expression.test(this._parts.hostname),c=d||e,g=(m=!c)&&h&&h.has(this._parts.hostname),f=m&&b.idn_expression.test(this._parts.hostname),k=m&&b.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return p;case "absolute":return!p;case "domain":case "name":return m;case "sld":return g;case "ip":return c;case "ip4":case "ipv4":case "inet4":return d;case "ip6":case "ipv6":case "inet6":return e; -case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var G=e.protocol,H=e.port,I=e.hostname;e.protocol=function(a,c){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(b.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return G.call(this,a,c)};e.scheme=e.protocol;e.port=function(a,c){if(this._parts.urn)return void 0===a?"":this;void 0!==a&&(0===a&& -(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),b.ensureValidPort(a)));return H.call(this,a,c)};e.hostname=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var d={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==b.parseHost(a,d))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=d.hostname;this._parts.preventInvalidHostname&&b.ensureValidHostname(a,this._parts.protocol)}return I.call(this,a,c)};e.origin=function(a, -c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=this.protocol();return this.authority()?(d?d+"://":"")+this.authority():""}d=b(a);this.protocol(d.protocol()).authority(d.authority()).build(!c);return this};e.host=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildHost(this._parts):"";if("/"!==b.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this}; -e.authority=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildAuthority(this._parts):"";if("/"!==b.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this};e.userinfo=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=b.buildUserinfo(this._parts);return d?d.substring(0,d.length-1):d}"@"!==a[a.length-1]&&(a+="@");b.parseUserinfo(a, -this._parts);this.build(!c);return this};e.resource=function(a,c){if(void 0===a)return this.path()+this.search()+this.hash();var d=b.parse(a);this._parts.path=d.path;this._parts.query=d.query;this._parts.fragment=d.fragment;this.build(!c);return this};e.subdomain=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,d)||""}d=this._parts.hostname.length- -this.domain().length;d=this._parts.hostname.substring(0,d);d=new RegExp("^"+q(d));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&b.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(d,a);this.build(!c);return this};e.domain=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d= -this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+"$"),this._parts.hostname= -this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf(".");b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(b, -a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return""; -if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1;d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a, -c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/");d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0=== -a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e,a));this.build(!c);return this};e.segment= -function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1);e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;ad.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+ +"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf(".");b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname= +this._parts.hostname.replace(b,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&& +!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1;d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c); +return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/");d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix= +function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e, +a));this.build(!c);return this};e.segment=function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1);e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;a that is not an image return undefined; } - + // NOTE: as we use a static mapping from element to attribute, // the HTML5 attribute issue should not come up again // https://github.com/medialize/URI.js/issues/69 @@ -120,17 +120,17 @@ var $this = this.first(); var elem = $this.get(0); var property = getUriProperty(elem); - + if (!property) { throw new Error('Element "' + elem.nodeName + '" does not have either property: href, src, action, cite'); } - + if (uri !== undefined) { var old = $this.data('uri'); if (old) { return old.href(uri); } - + if (!(uri instanceof URI)) { uri = URI(uri || ''); } @@ -142,7 +142,7 @@ uri = URI($this.attr(property) || ''); } } - + uri._dom_element = elem; uri._dom_attribute = property; uri.normalize(); @@ -164,7 +164,7 @@ this._string = URI.build(this._parts); this._deferred_build = false; } - + return this; }; @@ -173,12 +173,12 @@ var pseudoArgs = /^([a-zA-Z]+)\s*([\^\$*]?=|:)\s*(['"]?)(.+)\3|^\s*([a-zA-Z0-9]+)\s*$/; function uriPseudo (elem, text) { var match, property, uri; - + // skip anything without src|href|action and bad :uri() syntax if (!getUriProperty(elem) || !text) { return false; } - + match = text.match(pseudoArgs); if (!match || (!match[5] && match[2] !== ':' && !compare[match[2]])) { @@ -188,7 +188,7 @@ } uri = $(elem).uri(); - + if (match[5]) { return uri.is(match[5]); } else if (match[2] === ':') { @@ -197,7 +197,7 @@ // filers seem to fail silently return false; } - + return compare[property](uri, match[4]); } else { property = match[1].toLowerCase(); @@ -205,7 +205,7 @@ // filers seem to fail silently return false; } - + return compare[match[2]](uri[property](), match[4], property); } diff --git a/src/jquery.URI.min.js b/src/jquery.URI.min.js index ee4fc37f..dc19566d 100644 --- a/src/jquery.URI.min.js +++ b/src/jquery.URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.19.0 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.19.1 http://medialize.github.io/URI.js/ */ /* build contains: jquery.URI.js */ (function(d,e){"object"===typeof module&&module.exports?module.exports=e(require("jquery"),require("./URI")):"function"===typeof define&&define.amd?define(["jquery","./URI"],e):e(d.jQuery,d.URI)})(this,function(d,e){function h(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function k(a){var b=a.nodeName.toLowerCase();if("input"!==b||"image"===a.type)return e.domAttributes[b]}function n(a){return{get:function(b){return d(b).uri()[a]()},set:function(b,c){d(b).uri()[a](c);return c}}}function l(a, b){if(!k(a)||!b)return!1;var c=b.match(p);if(!c||!c[5]&&":"!==c[2]&&!g[c[2]])return!1;var e=d(a).uri();if(c[5])return e.is(c[5]);if(":"===c[2]){var f=c[1].toLowerCase()+":";return g[f]?g[f](e,c[4]):!1}f=c[1].toLowerCase();return m[f]?g[c[2]](e[f](),c[4],f):!1}var m={},g={"=":function(a,b){return a===b},"^=":function(a,b){return!!(a+"").match(new RegExp("^"+h(b),"i"))},"$=":function(a,b){return!!(a+"").match(new RegExp(h(b)+"$","i"))},"*=":function(a,b,c){"directory"===c&&(a+="/");return!!(a+"").match(new RegExp(h(b),