From e62e0bdc18a71404686b85e7648e00602de8d3ec Mon Sep 17 00:00:00 2001 From: Alasdair Mercer Date: Thu, 15 Mar 2012 11:01:22 +0000 Subject: [PATCH] #87 customizing jQuery-URL-Parser plugin to prevent it from decoding the URL --- src/vendor/jquery.url.min.js | 160 ++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/src/vendor/jquery.url.min.js b/src/vendor/jquery.url.min.js index 2f5a448..1388783 100644 --- a/src/vendor/jquery.url.min.js +++ b/src/vendor/jquery.url.min.js @@ -1 +1,159 @@ -(function(a,b){function j(a,b){var c=decodeURI(a),e=f[b||!1?"strict":"loose"].exec(c),i={attr:{},param:{},seg:{}},j=14;while(j--)i.attr[d[j]]=e[j]||"";i.param.query={};i.param.fragment={};i.attr.query.replace(g,function(a,b,c){b&&(i.param.query[b]=c)});i.attr.fragment.replace(h,function(a,b,c){b&&(i.param.fragment[b]=c)});i.seg.path=i.attr.path.replace(/^\/+|\/+$/g,"").split("/");i.seg.fragment=i.attr.fragment.replace(/^\/+|\/+$/g,"").split("/");i.attr.base=i.attr.host?i.attr.protocol+"://"+i.attr.host+(i.attr.port?":"+i.attr.port:""):"";return i}function i(a){var d=a.tagName;return d===b?d:c[d.toLowerCase()]}var c={a:"href",base:"href",form:"action",iframe:"src",img:"src",link:"href",script:"src"},d=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","fragment"],e={anchor:"fragment"},f={loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/},g=/(?:^|&|;)([^&=;]*)=?([^&;]*)/g,h=/(?:^|&|;)([^&=;]*)=?([^&;]*)/g;a.fn.url=function(b){var c={strict:b,url:""};this.length&&(c.url=a(this).attr(i(this[0]))||"");return a.url(c)};a.url=function(a){var c={},d=!1,f="";if(typeof a=="string")f=a;else{a=a||{};d=a.strict||d;f=a.url===b?window.location.toString():a.url}c={attr:function(a){a=e[a]||a;return a!==b?this.data.attr[a]:this.data.attr},data:j(f,d),fparam:function(a){return a!==b?this.data.param.fragment[a]:this.data.param.fragment},fsegment:function(a){if(a===b)return this.data.seg.fragment;a=a<0?this.data.seg.fragment.length+a:a-1;return this.data.seg.fragment[a]},param:function(a){return a!==b?this.data.param.query[a]:this.data.param.query},segment:function(a){if(a===b)return this.data.seg.path;a=a<0?this.data.seg.path.length+a:a-1;return this.data.seg.path[a]}};return c}})(jQuery) \ No newline at end of file +// JQuery URL Parser plugin - https://github.com/allmarkedup/jQuery-URL-Parser +// Written by Mark Perkins, mark@allmarkedup.com +// License: http://unlicense.org/ (i.e. do what you want with it!) + +;(function($, undefined) { + + var tag2attr = { + a : 'href', + img : 'src', + form : 'action', + base : 'href', + script : 'src', + iframe : 'src', + link : 'href' + }, + + key = ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","fragment"], // keys available to query + + aliases = { "anchor" : "fragment" }, // aliases for backwards compatability + + parser = { + strict : /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, //less intuitive, more accurate to the specs + loose : /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs + }, + + querystring_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g, // supports both ampersand and semicolon-delimted query string key/value pairs + + fragment_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g; // supports both ampersand and semicolon-delimted fragment key/value pairs + + function parseUri( url, strictMode ) + { + var str = url, + res = parser[ strictMode || false ? "strict" : "loose" ].exec( str ), + uri = { attr : {}, param : {}, seg : {} }, + i = 14; + + while ( i-- ) + { + uri.attr[ key[i] ] = res[i] || ""; + } + + // build query and fragment parameters + + uri.param['query'] = {}; + uri.param['fragment'] = {}; + + uri.attr['query'].replace( querystring_parser, function ( $0, $1, $2 ){ + if ($1) + { + uri.param['query'][$1] = $2; + } + }); + + uri.attr['fragment'].replace( fragment_parser, function ( $0, $1, $2 ){ + if ($1) + { + uri.param['fragment'][$1] = $2; + } + }); + + // split path and fragement into segments + + uri.seg['path'] = uri.attr.path.replace(/^\/+|\/+$/g,'').split('/'); + + uri.seg['fragment'] = uri.attr.fragment.replace(/^\/+|\/+$/g,'').split('/'); + + // compile a 'base' domain attribute + + uri.attr['base'] = uri.attr.host ? uri.attr.protocol+"://"+uri.attr.host + (uri.attr.port ? ":"+uri.attr.port : '') : ''; + + return uri; + }; + + function getAttrName( elm ) + { + var tn = elm.tagName; + if ( tn !== undefined ) return tag2attr[tn.toLowerCase()]; + return tn; + } + + $.fn.url = function( strictMode ) + { + var url = ''; + + if ( this.length ) + { + url = $(this).attr( getAttrName(this[0]) ) || ''; + } + + return $.url( url, strictMode ); + }; + + $.url = function( url, strictMode ) + { + if ( arguments.length === 1 && url === true ) + { + strictMode = true; + url = undefined; + } + + strictMode = strictMode || false; + url = url || window.location.toString(); + + return { + + data : parseUri(url, strictMode), + + // get various attributes from the URI + attr : function( attr ) + { + attr = aliases[attr] || attr; + return attr !== undefined ? this.data.attr[attr] : this.data.attr; + }, + + // return query string parameters + param : function( param ) + { + return param !== undefined ? this.data.param.query[param] : this.data.param.query; + }, + + // return fragment parameters + fparam : function( param ) + { + return param !== undefined ? this.data.param.fragment[param] : this.data.param.fragment; + }, + + // return path segments + segment : function( seg ) + { + if ( seg === undefined ) + { + return this.data.seg.path; + } + else + { + seg = seg < 0 ? this.data.seg.path.length + seg : seg - 1; // negative segments count from the end + return this.data.seg.path[seg]; + } + }, + + // return fragment segments + fsegment : function( seg ) + { + if ( seg === undefined ) + { + return this.data.seg.fragment; + } + else + { + seg = seg < 0 ? this.data.seg.fragment.length + seg : seg - 1; // negative segments count from the end + return this.data.seg.fragment[seg]; + } + } + + }; + + }; + +})(jQuery); \ No newline at end of file