Skip to content

fix: escape CLI span JSON strings - #9

Open
localai-org-maint-bot wants to merge 1 commit into
localai-org:masterfrom
localai-org-maint-bot:fix-cli-json-escaping
Open

localai-org-maint-bot wants to merge 1 commit into
localai-org:masterfrom
localai-org-maint-bot:fix-cli-json-escaping

Conversation

@localai-org-maint-bot

@localai-org-maint-bot localai-org-maint-bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Fixes #8.

Both --classify and token/offset span output currently insert raw text into JSON strings. Quotes, backslashes, and control bytes make the output invalid; embedded NUL also truncates the span.

Quote labels and span text through one length-aware helper. Preserve UTF-8 bytes and byte offsets. Add a model-independent CTest target covering escaping, embedded NUL, and bounded slices.

Validation: git diff --check passes. Both GCC release and Clang sanitizer CI builds and model-independent CTest suites pass, including the new test. Local native tests were unavailable because this host has no C++ compiler or CMake. Model inference was not run.

To run the new test without model assets or ggml:

c++ -std=c++17 -Wall -Wextra -Werror tests/test_json.cpp -o /tmp/pf-test-json
/tmp/pf-test-json

It is also registered as test_json in the normal CTest suite. End-to-end output from both CLI modes with model assets and a JSON parser remains untested; the native builds compile both call sites and the model-independent test checks their shared serializer.

Quote labels and span text in both CLI output paths so JSON consumers
can read quotes, backslashes, and control bytes. Use explicit lengths
to preserve embedded NUL bytes and span boundaries.

Add a model-independent serialization test. Native validation remains
pending because the maintainer host has no C++ compiler or CMake.

Assisted-by: Codex:gpt-6
@localai-org-maint-bot
localai-org-maint-bot marked this pull request as ready for review October 11, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pf-cli --classify emits invalid JSON when span text contains quotes, backslashes, or control characters

1 participant