From 972bcb83a587fb6898da00156951f8b8d3b552b2 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 3 Jun 2016 21:18:20 +0200 Subject: [PATCH] First test implementation --- Uri/UriFactory.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index 1220095..db33c9f 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -25,25 +25,35 @@ /** * Parse uri * + * @param {string} str Url to parse + * @param {string} mode Parsing mode + * * @return {Object} * + * @throws {Error} + * * @function * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Uri.UriFactory.parseUrl = function (str) + jsOMS.Uri.UriFactory.parseUrl = function (str, mode) { + mode = typeof mode === 'undefined' ? 'php' : mode; + let query, key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'fragment' ], - mode = 'php', parser = { php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) }; + if(!parser.hasOwnProperty(mode)) { + throw new Error('Unexpected parsing mode.', 'UriFactory', 52); + } + let m = parser[mode].exec(str), uri = {}, i = 14; @@ -100,7 +110,7 @@ { overwrite = typeof overwrite !== 'undefined' ? overwrite : true; - if (overwrite || !jsOMS.Uri.UriFactory.uri.hasProperty(key)) { + if (overwrite || !jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) { jsOMS.Uri.UriFactory.uri[key] = value; return true;