fix(quotesdb): use char count for reason validation, remove duplicate CountRow in d1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
quotesdb
Elijah Voigt 3 months ago
parent eecdbba9d7
commit 995fff4046

@ -684,17 +684,12 @@ impl QuoteRepository for D1Repository {
/// with the given `quote_id` exists.
async fn create_report(&self, quote_id: &str, reason: Option<&str>) -> Result<(), DbError> {
// Step 1: verify the quote exists.
#[derive(serde::Deserialize)]
struct ExistsRow {
count: i64,
}
let exists_row = self
.db
.prepare("SELECT COUNT(*) AS count FROM quotes WHERE id = ?1")
.bind(&[JsValue::from_str(quote_id)])
.map_err(|e| DbError::Internal(e.to_string()))?
.first::<ExistsRow>(None)
.first::<CountRow>(None)
.await
.map_err(|e| DbError::Internal(e.to_string()))?;

@ -565,7 +565,7 @@ async fn report_handler(
let reason = body.and_then(|Json(input)| input.reason);
// Validate reason length — enforced here before the DB call.
if reason.as_deref().map(|r| r.len()).unwrap_or(0) > 256 {
if reason.as_deref().map(|r| r.chars().count()).unwrap_or(0) > 256 {
return error_response(
StatusCode::BAD_REQUEST,
"reason must be at most 256 characters",

Loading…
Cancel
Save