encode values before using in url (#81)

This commit is contained in:
austinried 2022-03-28 15:44:58 +09:00 committed by GitHub
parent 41f00ef3f1
commit 5169b726ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,13 +65,13 @@ export class SubsonicApiClient {
this.username = server.username this.username = server.username
this.params = new URLSearchParams() this.params = new URLSearchParams()
this.params.append('u', server.username) this.params.append('u', encodeURIComponent(server.username))
if (server.usePlainPassword) { if (server.usePlainPassword) {
this.params.append('p', server.plainPassword) this.params.append('p', encodeURIComponent(server.plainPassword))
} else { } else {
this.params.append('t', server.token) this.params.append('t', encodeURIComponent(server.token))
this.params.append('s', server.salt) this.params.append('s', encodeURIComponent(server.salt))
} }
this.params.append('v', '1.13.0') this.params.append('v', '1.13.0')
@ -79,16 +79,16 @@ export class SubsonicApiClient {
} }
private buildUrl(method: string, params?: { [key: string]: any }): string { private buildUrl(method: string, params?: { [key: string]: any }): string {
let query = this.params.toString() let urlParams = this.params.toString()
if (params) { if (params) {
const urlParams = this.obj2Params(params) const methodParams = this.obj2Params(params)
if (urlParams) { if (methodParams) {
query += '&' + urlParams.toString() urlParams += '&' + methodParams.toString()
} }
} }
// *.view was present on all method names in API 1.14.0 and earlier // *.view was present on all method names in API 1.14.0 and earlier
return `${this.address}/rest/${method}.view?${query}` return `${this.address}/rest/${method}.view?${urlParams}`
} }
private async apiGetXml(method: string, params?: { [key: string]: any }): Promise<Document> { private async apiGetXml(method: string, params?: { [key: string]: any }): Promise<Document> {
@ -123,7 +123,7 @@ export class SubsonicApiClient {
if (obj[key] === undefined || obj[key] === null) { if (obj[key] === undefined || obj[key] === null) {
continue continue
} }
params.append(key, String(obj[key])) params.append(key, encodeURIComponent(String(obj[key])))
} }
return params return params