From 1a0f328055f97fd8fff3a2cca9bd78d6581e32b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=99=E5=8C=85=E5=A6=96=E6=A2=A6?= Date: Thu, 16 Jan 2014 21:23:23 +0800 Subject: [PATCH 1/2] A patch that allow '@' appear in path or query-string $.url('http://domain.com/xxx@yyy'); => protocol=http, host=domain.com, directory=xxx@yyy $.url('/a@b', false); => user=/a, host=b $.url('/a@b', true); => directory=/a@b --- purl.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/purl.js b/purl.js index b5799c6..3dc60f6 100644 --- a/purl.js +++ b/purl.js @@ -34,10 +34,18 @@ loose : /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs }, - isint = /^[0-9]+$/; + isint = /^[0-9]+$/, + AuthPath = { + strict : /^[0-9a-zA-Z]*:?\/\/[^@\/]+\/.*@.*/, // only allow "//domain.com/xxx@yyy" "http://domain.com/xxx@yyy" + loose : /^([0-9a-zA-Z]*:?\/\/[^@\/]+)?\/.*@.*/ // also allow "/xxx@yyy", note : relative path "xxx@yyy" is a valid "user@host" so not support + }; + function patchAuthority( str, strictMode ){ + return AuthPath[ strictMode || false ? 'strict' : 'loose' ].test(str)? str.replace(/^([0-9a-zA-Z]*:?\/\/)/,'$1:@') : str; + } + function parseUri( url, strictMode ) { - var str = decodeURI( url ), + var str = patchAuthority(decodeURI( url ), strictMode), res = parser[ strictMode || false ? 'strict' : 'loose' ].exec( str ), uri = { attr : {}, param : {}, seg : {} }, i = 14; From 1e2c1c701cd196bc8d6b919918b8edcb101eb2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=99=E5=8C=85=E5=A6=96=E6=A2=A6?= Date: Thu, 16 Jan 2014 21:28:56 +0800 Subject: [PATCH 2/2] change tab to spaces! --- purl.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/purl.js b/purl.js index 3dc60f6..5778c5a 100644 --- a/purl.js +++ b/purl.js @@ -35,15 +35,15 @@ }, isint = /^[0-9]+$/, - AuthPath = { - strict : /^[0-9a-zA-Z]*:?\/\/[^@\/]+\/.*@.*/, // only allow "//domain.com/xxx@yyy" "http://domain.com/xxx@yyy" - loose : /^([0-9a-zA-Z]*:?\/\/[^@\/]+)?\/.*@.*/ // also allow "/xxx@yyy", note : relative path "xxx@yyy" is a valid "user@host" so not support + AuthPath = { + strict : /^[0-9a-zA-Z]*:?\/\/[^@\/]+\/.*@.*/, // only allow "//domain.com/xxx@yyy" "http://domain.com/xxx@yyy" + loose : /^([0-9a-zA-Z]*:?\/\/[^@\/]+)?\/.*@.*/ // also allow "/xxx@yyy", note : relative path "xxx@yyy" is a valid "user@host" so not support }; - function patchAuthority( str, strictMode ){ - return AuthPath[ strictMode || false ? 'strict' : 'loose' ].test(str)? str.replace(/^([0-9a-zA-Z]*:?\/\/)/,'$1:@') : str; - } - + function patchAuthority( str, strictMode ){ + return AuthPath[ strictMode || false ? 'strict' : 'loose' ].test(str)? str.replace(/^([0-9a-zA-Z]*:?\/\/)/,'$1:@') : str; + } + function parseUri( url, strictMode ) { var str = patchAuthority(decodeURI( url ), strictMode), res = parser[ strictMode || false ? 'strict' : 'loose' ].exec( str ),