Skip to content

[QTI] A QTI item declaring a non-UTF-8 encoding is published with garbled text #6283

Description

@rtibblesbot

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: unstable

Observed behavior

  • raw_data is a str. Validation and publish encode it to UTF-8 bytes (validate_qti_item, _create_native_qti_item in utils/assessment/qti/archive.py).
  • If the item's XML declaration names another encoding, e.g. encoding="ISO-8859-1", the bytes are decoded under that declared encoding.
  • So non-ASCII text is mis-decoded: café reaches Kolibri as café.
  • The item passes validate_qti_item, so nothing flags it.

Errors and logs

None; the publish succeeds.

Expected behavior

  • The published item's text matches raw_data, whatever encoding its declaration names.
  • Or the item is rejected at validation.

User-facing consequences

Learners see garbled characters in every non-ASCII word of the item.

Steps to reproduce

  1. In VALID_CHOICE_ITEM (tests/utils/qti/test_validation.py), replace encoding="UTF-8" with encoding="ISO-8859-1" and prefix the prompt text with café .
  2. validate_qti_item(xml).is_valid is True.
  3. Pass it through set_qti_item_language(xml, "fr") and strip_studio_attributes, encode to UTF-8 as _create_native_qti_item does, then parse the bytes with lxml.etree.fromstring.
  4. The prompt text reads café Select the correct answer.

Context

Studio unstable at ec6eb522d.

AI usage

Claude Code found this while reviewing #6235 and drafted this issue. The reproduction was run against upstream/unstable and the #6235 branch, with the same result on both.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions