mirror of
https://git.hmsn.ink/kospo/helptalk/api.git
synced 2026-03-20 09:33:46 +09:00
first
This commit is contained in:
26
sample/prod/talk/bundle/mithril-2.2.2/querystring/build.js
Normal file
26
sample/prod/talk/bundle/mithril-2.2.2/querystring/build.js
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict"
|
||||
|
||||
module.exports = function(object) {
|
||||
if (Object.prototype.toString.call(object) !== "[object Object]") return ""
|
||||
|
||||
var args = []
|
||||
for (var key in object) {
|
||||
destructure(key, object[key])
|
||||
}
|
||||
|
||||
return args.join("&")
|
||||
|
||||
function destructure(key, value) {
|
||||
if (Array.isArray(value)) {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
destructure(key + "[" + i + "]", value[i])
|
||||
}
|
||||
}
|
||||
else if (Object.prototype.toString.call(value) === "[object Object]") {
|
||||
for (var i in value) {
|
||||
destructure(key + "[" + i + "]", value[i])
|
||||
}
|
||||
}
|
||||
else args.push(encodeURIComponent(key) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : ""))
|
||||
}
|
||||
}
|
||||
51
sample/prod/talk/bundle/mithril-2.2.2/querystring/parse.js
Normal file
51
sample/prod/talk/bundle/mithril-2.2.2/querystring/parse.js
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict"
|
||||
|
||||
function decodeURIComponentSave(str) {
|
||||
try {
|
||||
return decodeURIComponent(str)
|
||||
} catch(err) {
|
||||
return str
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function(string) {
|
||||
if (string === "" || string == null) return {}
|
||||
if (string.charAt(0) === "?") string = string.slice(1)
|
||||
|
||||
var entries = string.split("&"), counters = {}, data = {}
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var entry = entries[i].split("=")
|
||||
var key = decodeURIComponentSave(entry[0])
|
||||
var value = entry.length === 2 ? decodeURIComponentSave(entry[1]) : ""
|
||||
|
||||
if (value === "true") value = true
|
||||
else if (value === "false") value = false
|
||||
|
||||
var levels = key.split(/\]\[?|\[/)
|
||||
var cursor = data
|
||||
if (key.indexOf("[") > -1) levels.pop()
|
||||
for (var j = 0; j < levels.length; j++) {
|
||||
var level = levels[j], nextLevel = levels[j + 1]
|
||||
var isNumber = nextLevel == "" || !isNaN(parseInt(nextLevel, 10))
|
||||
if (level === "") {
|
||||
var key = levels.slice(0, j).join()
|
||||
if (counters[key] == null) {
|
||||
counters[key] = Array.isArray(cursor) ? cursor.length : 0
|
||||
}
|
||||
level = counters[key]++
|
||||
}
|
||||
// Disallow direct prototype pollution
|
||||
else if (level === "__proto__") break
|
||||
if (j === levels.length - 1) cursor[level] = value
|
||||
else {
|
||||
// Read own properties exclusively to disallow indirect
|
||||
// prototype pollution
|
||||
var desc = Object.getOwnPropertyDescriptor(cursor, level)
|
||||
if (desc != null) desc = desc.value
|
||||
if (desc == null) cursor[level] = desc = isNumber ? [] : {}
|
||||
cursor = desc
|
||||
}
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
Reference in New Issue
Block a user