From 3ea4e49686605d3cb4778e8126b1048fb224d172 Mon Sep 17 00:00:00 2001 From: Ilyas Hallak Date: Wed, 1 Oct 2025 21:36:59 +0200 Subject: [PATCH] fix: Properly URL-encode labels parameter for API requests - Add quotes around label values to match API requirements - Fix label filtering for labels with spaces (e.g. 'aa aa') - Ensure proper URL encoding as required by server - Maintains existing pagination and filtering functionality --- readeck/Data/API/API.swift | 4 +++- readeck/Data/Utils/LabelUtils.swift | 12 +++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/readeck/Data/API/API.swift b/readeck/Data/API/API.swift index 455b6eb..57cb0f1 100644 --- a/readeck/Data/API/API.swift +++ b/readeck/Data/API/API.swift @@ -241,7 +241,9 @@ class API: PAPI { } if let tag { - queryItems.append(URLQueryItem(name: "labels", value: tag)) + // URL-encode label with quotes for proper API handling + let encodedTag = "\"\(tag)\"" + queryItems.append(URLQueryItem(name: "labels", value: encodedTag)) } if !queryItems.isEmpty { diff --git a/readeck/Data/Utils/LabelUtils.swift b/readeck/Data/Utils/LabelUtils.swift index 5b2b24e..3cc9141 100644 --- a/readeck/Data/Utils/LabelUtils.swift +++ b/readeck/Data/Utils/LabelUtils.swift @@ -1,14 +1,12 @@ import Foundation struct LabelUtils { - /// Splits a label input string by spaces and returns individual trimmed labels - /// - Parameter input: The input string containing one or more labels separated by spaces - /// - Returns: Array of individual trimmed labels, excluding empty strings + /// Processes a label input string and returns it as a single trimmed label + /// - Parameter input: The input string containing a label (spaces are allowed) + /// - Returns: Array containing the trimmed label, or empty array if input is empty static func splitLabelsFromInput(_ input: String) -> [String] { - return input - .components(separatedBy: " ") - .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } - .filter { !$0.isEmpty } + let trimmed = input.trimmingCharacters(in: .whitespacesAndNewlines) + return trimmed.isEmpty ? [] : [trimmed] } /// Filters out labels that already exist in current or available labels