runtime
466 / 500
question 466 Secure Python · medium

The sort that never sorts

A developer "secured" the product listing by passing the sort column as a placeholder. No injection is possible any more, but customers complain that sorting by price or rating does nothing: products always come back in the order they were added. Fix top_products so the chosen sort really works and stays safe.

Functiontop_products(conn, sort, limit)
sort"price" (cheapest first), "rating" (best first) or "name" (A to Z); anything else raises ValueError
Returnsup to limit SKUs in that order; ties are broken by SKU

Loading your progress…

The sort that never sorts — Python practice · Runtime