forked from Blendman974/faceclaw
Fix a bug where searching EvenHub for a string with spaces would fail
This commit is contained in:
1 parent
5f2799f569
commit
f4751ad480
2 files changed
+20
-12
No files matched your search
@@ -18,6 +18,7 @@
|
|||||||
* Phone preview is centered on the phone screen when apps are not maximized
|
* Phone preview is centered on the phone screen when apps are not maximized
|
||||||
* iOS: Add missing EvenHub icons on the phone home screen
|
* iOS: Add missing EvenHub icons on the phone home screen
|
||||||
* Fix a bug where album art and track display could get out of sync if you advance twice quickly
|
* Fix a bug where album art and track display could get out of sync if you advance twice quickly
|
||||||
|
* Fix a bug where EvenHub searches with spaces in the search term would fail
|
||||||
|
|
||||||
## 0.8.3 - 2026-10-10
|
## 0.8.3 - 2026-10-10
|
||||||
|
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ export class EvenHubApiClient {
|
|||||||
const token = options.token ?? "";
|
const token = options.token ?? "";
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
common,
|
common,
|
||||||
sign: hmacSign(signingParts(method, path, common, query, token, body)),
|
sign: hmacSign(signingParts(method, path, common, signedQuery(options.query ?? {}), token, body)),
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
};
|
};
|
||||||
if (token) headers.token = token;
|
if (token) headers.token = token;
|
||||||
@@ -266,7 +266,7 @@ export function signingParts(
|
|||||||
body = "",
|
body = "",
|
||||||
): string {
|
): string {
|
||||||
const parts = [method.toUpperCase(), path, common];
|
const parts = [method.toUpperCase(), path, common];
|
||||||
if (query) parts.push(normalizeQuery(query));
|
if (query) parts.push(query);
|
||||||
if (token) parts.push(token);
|
if (token) parts.push(token);
|
||||||
if (body) parts.push(body);
|
if (body) parts.push(body);
|
||||||
return parts.sort().join("\n");
|
return parts.sort().join("\n");
|
||||||
@@ -320,19 +320,26 @@ function buildCommon(version: 1 | 3): string {
|
|||||||
return Object.entries(fields).map(([key, value]) => `${formEncode(key)}=${formEncode(String(value))}`).join("&");
|
return Object.entries(fields).map(([key, value]) => `${formEncode(key)}=${formEncode(String(value))}`).join("&");
|
||||||
}
|
}
|
||||||
|
|
||||||
function encodePairs(values: Record<string, string | number>): string {
|
/** Query entries sorted by key in code-unit order (Dart's default String sort). */
|
||||||
|
function sortedPairs(values: Record<string, string | number>): [string, string][] {
|
||||||
return Object.entries(values)
|
return Object.entries(values)
|
||||||
.sort(([a], [b]) => a.localeCompare(b))
|
.map(([key, value]): [string, string] => [key, String(value)])
|
||||||
.map(([key, value]) => `${formEncode(key)}=${formEncode(String(value))}`)
|
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
||||||
.join("&");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeQuery(query: string): string {
|
function encodePairs(values: Record<string, string | number>): string {
|
||||||
return query
|
return sortedPairs(values).map(([key, value]) => `${formEncode(key)}=${formEncode(value)}`).join("&");
|
||||||
.split("&")
|
}
|
||||||
.filter(Boolean)
|
|
||||||
.sort((a, b) => a.split("=", 1)[0]!.localeCompare(b.split("=", 1)[0]!))
|
/**
|
||||||
.join("&");
|
* The query as it participates in signing: sorted raw `key=value` pairs, NOT
|
||||||
|
* URL-encoded (SignatureUtil.calculateSignature in the official 2.2.8 Dart
|
||||||
|
* image). The server signs the decoded parameters, so signing the encoded
|
||||||
|
* form only matched when encoding was a no-op (a search for "two words" was
|
||||||
|
* rejected with HTTP 406).
|
||||||
|
*/
|
||||||
|
function signedQuery(values: Record<string, string | number>): string {
|
||||||
|
return sortedPairs(values).map(([key, value]) => `${key}=${value}`).join("&");
|
||||||
}
|
}
|
||||||
|
|
||||||
function formEncode(value: string): string {
|
function formEncode(value: string): string {
|
||||||
|
|||||||
Reference in new issue
Block a user