diff --git a/Gruntfile.js b/Gruntfile.js index afcd67b..71ab1c6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -28,7 +28,9 @@ module.exports = function(grunt) { "src/About.js" ], browserFileList = coreFileList.slice(), - nodeFileList = coreFileList.slice(); + nodeFileList = coreFileList.slice(), + pkg, + bower; browserFileList.push( "src/Environment/Browser.js" @@ -37,9 +39,16 @@ module.exports = function(grunt) { "src/Environment/Node.js" ); + pkg = grunt.file.readJSON("package.json"); + bower = grunt.file.readJSON("bower.json"); + + if (pkg.version !== bower.version) { + grunt.fail.fatal("package.json and bower.json versions do not match"); + } + // Project configuration. grunt.initConfig({ - pkg: grunt.file.readJSON("package.json"), + pkg: pkg, watch: { files: ["src/**/*.js"], diff --git a/src/Utils.js b/src/Utils.js index f14358e..2f77603 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -240,26 +240,50 @@ TinCan client library @private */ parseURL: function (url) { - var parts = String(url).split("?"), - pairs, - pair, - i, - params = {} - ; - if (parts.length === 2) { - pairs = parts[1].split("&"); - for (i = 0; i < pairs.length; i += 1) { - pair = pairs[i].split("="); - if (pair.length === 2 && pair[0]) { - params[pair[0]] = decodeURIComponent(pair[1]); - } + // + // see http://stackoverflow.com/a/21553982 + // and http://stackoverflow.com/a/2880929 + // + var reURLInformation, + match, + result, + paramMatch, + pl = /\+/g, // Regex for replacing addition symbol with a space + search = /([^&=]+)=?([^&]*)/g, + decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }; + + reURLInformation = new RegExp( + [ + "^(https?:)//", // protocol + "(([^:/?#]*)(?::([0-9]+))?)", // host (hostname and port) + "(/[^?#]*)", // pathname + "(\\?[^#]*|)", // search + "(#.*|)$" // hash + ].join("") + ); + match = url.match(reURLInformation); + result = { + protocol: match[1], + host: match[2], + hostname: match[3], + port: match[4], + pathname: match[5], + search: match[6], + hash: match[7], + params: {} + }; + + // 'path' is for backwards compatibility + result.path = result.protocol + "//" + result.host + result.pathname; + + if (result.search !== "") { + // extra parens to let jshint know this is an expression + while ((paramMatch = search.exec(result.search.substring(1)))) { + result.params[decode(paramMatch[1])] = decode(paramMatch[2]); } } - return { - path: parts[0], - params: params - }; + return result; }, /** diff --git a/test/index.html b/test/index.html index 1878ab6..bccff38 100644 --- a/test/index.html +++ b/test/index.html @@ -20,42 +20,59 @@
-