fix: correct tojson|safe usage in templates and update validator

- Remove |safe from |tojson in HTML attributes (x-data) - quotes must
  become " for browsers to parse correctly
- Update LANG-002 and LANG-003 architecture rules to document correct
  |tojson usage patterns:
  - HTML attributes: |tojson (no |safe)
  - Script blocks: |tojson|safe
- Fix validator to warn when |tojson|safe is used in x-data (breaks
  HTML attribute parsing)
- Improve code quality across services, APIs, and tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-13 22:59:51 +01:00
parent 94d268f330
commit 9920430b9e
123 changed files with 1408 additions and 840 deletions

View File

@@ -108,8 +108,7 @@ class TestProductService:
assert existing_product_id in str(exc_info.value)
assert exc_info.value.status_code == 409
assert (
exc_info.value.details.get("marketplace_product_id")
== existing_product_id
exc_info.value.details.get("marketplace_product_id") == existing_product_id
)
def test_create_product_invalid_price(self, db):
@@ -224,7 +223,9 @@ class TestProductService:
assert "Invalid GTIN format" in str(exc_info.value)
assert exc_info.value.details.get("field") == "gtin"
def test_update_product_empty_title_preserves_existing(self, db, test_marketplace_product):
def test_update_product_empty_title_preserves_existing(
self, db, test_marketplace_product
):
"""Test updating product with empty title preserves existing title in translation"""
original_title = test_marketplace_product.get_title()
update_data = MarketplaceProductUpdate(title="")
@@ -275,7 +276,9 @@ class TestProductService:
self, db, test_marketplace_product_with_inventory
):
"""Test getting inventory info for product with inventory."""
marketplace_product = test_marketplace_product_with_inventory["marketplace_product"]
marketplace_product = test_marketplace_product_with_inventory[
"marketplace_product"
]
inventory = test_marketplace_product_with_inventory["inventory"]
inventory_info = self.service.get_inventory_info(db, marketplace_product.gtin)
@@ -352,7 +355,10 @@ class TestMarketplaceProductServiceAdmin:
# Find our test product in results
found = False
for p in products:
if p["marketplace_product_id"] == test_marketplace_product.marketplace_product_id:
if (
p["marketplace_product_id"]
== test_marketplace_product.marketplace_product_id
):
found = True
assert p["id"] == test_marketplace_product.id
assert p["marketplace"] == test_marketplace_product.marketplace
@@ -429,9 +435,7 @@ class TestMarketplaceProductServiceAdmin:
def test_get_admin_product_detail(self, db, test_marketplace_product):
"""Test getting admin product detail by ID."""
product = self.service.get_admin_product_detail(
db, test_marketplace_product.id
)
product = self.service.get_admin_product_detail(db, test_marketplace_product.id)
assert product["id"] == test_marketplace_product.id
assert (