Clarify pathname docs, follow spec with fragments (#2448)
* Clarify pathname docs, follow spec with fragments - Valid URLs must not contain a `#` within its fragment. https://github.com/MithrilJS/mithril.js/issues/2445 - Our docs were a little confusing and misleading - `m.pathname` isn't aware of URLs, just path names. - Removed the relevant extension to `m.parseQueryString` required to support the hash parsing extension. Now we just shave it off and ignore it. - Fix support for arbitrary prefixes, so prefixes like `?#` are handled correctly. - Add a bunch of tests to cover various areas of confusion and unusual edge cases. * Update with PR [skip ci]
This commit is contained in:
parent
9e9b89d900
commit
85bfd0f77d
15 changed files with 85 additions and 127 deletions
|
|
@ -7,7 +7,7 @@ o.spec("parseURL", function() {
|
|||
var root = {protocol: "http:", hostname: "localhost", port: "", pathname: "/"}
|
||||
|
||||
o.spec("full URL", function() {
|
||||
o("parses full URL", function() {
|
||||
o("parses full http URL", function() {
|
||||
var data = parseURL("http://www.google.com:80/test?a=b#c")
|
||||
o(data.protocol).equals("http:")
|
||||
o(data.hostname).equals("www.google.com")
|
||||
|
|
@ -16,6 +16,15 @@ o.spec("parseURL", function() {
|
|||
o(data.search).equals("?a=b")
|
||||
o(data.hash).equals("#c")
|
||||
})
|
||||
o("parses full websocket URL", function() {
|
||||
var data = parseURL("ws://www.google.com:80/test?a=b#c")
|
||||
o(data.protocol).equals("ws:")
|
||||
o(data.hostname).equals("www.google.com")
|
||||
o(data.port).equals("80")
|
||||
o(data.pathname).equals("/test")
|
||||
o(data.search).equals("?a=b")
|
||||
o(data.hash).equals("#c")
|
||||
})
|
||||
o("parses full URL omitting optionals", function() {
|
||||
var data = parseURL("http://www.google.com")
|
||||
o(data.protocol).equals("http:")
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ module.exports = function() {
|
|||
}
|
||||
this.open = function(method, url, async, user, password) {
|
||||
var urlData = parseURL(url, {protocol: "http:", hostname: "localhost", port: "", pathname: "/"})
|
||||
args.rawUrl = url
|
||||
args.method = method
|
||||
args.pathname = urlData.pathname
|
||||
args.search = urlData.search
|
||||
|
|
@ -56,7 +57,7 @@ module.exports = function() {
|
|||
var self = this
|
||||
if(!aborted) {
|
||||
var handler = routes[args.method + " " + args.pathname] || serverErrorHandler.bind(null, args.pathname)
|
||||
var data = handler({url: args.pathname, query: args.search || {}, body: body || null})
|
||||
var data = handler({rawUrl: args.rawUrl, url: args.pathname, query: args.search || {}, body: body || null})
|
||||
self.status = data.status
|
||||
// Match spec
|
||||
if (self.responseType === "json") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue