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
|
|
@ -2,12 +2,11 @@
|
|||
|
||||
// The extra `data` parameter is for if you want to append to an existing
|
||||
// parameters object.
|
||||
module.exports = function(string, data) {
|
||||
if (data == null) data = {}
|
||||
module.exports = function(string) {
|
||||
if (string === "" || string == null) return {}
|
||||
if (string.charAt(0) === "?") string = string.slice(1)
|
||||
|
||||
var entries = string.split("&"), counters = {}
|
||||
var entries = string.split("&"), counters = {}, data = {}
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var entry = entries[i].split("=")
|
||||
var key = decodeURIComponent(entry[0])
|
||||
|
|
|
|||
|
|
@ -97,16 +97,4 @@ o.spec("parseQueryString", function() {
|
|||
var data = parseQueryString("a=1&b=2&a=3")
|
||||
o(data).deepEquals({a: "3", b: "2"})
|
||||
})
|
||||
o("continues to append to arrays between calls", function() {
|
||||
var data = {}
|
||||
parseQueryString("a[]=1&a[]=2", data)
|
||||
parseQueryString("a[]=3&a[]=4", data)
|
||||
o(data).deepEquals({a: ["1", "2", "3", "4"]})
|
||||
})
|
||||
o("continues to append to objects between calls", function() {
|
||||
var data = {}
|
||||
parseQueryString("a[b]=1&a[c]=2", data)
|
||||
parseQueryString("a[d]=3&a[e]=4", data)
|
||||
o(data).deepEquals({a: {b: "1", c: "2", d: "3", e: "4"}})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue