Skip to content

Fix text() alphabet drawing characters outside the alphabet - #147

Open
Chirag6722 wants to merge 1 commit into
hegeldev:mainfrom
Chirag6722:fix/146-alphabet-empty-categories
Open

Chirag6722 wants to merge 1 commit into
hegeldev:mainfrom
Chirag6722:fix/146-alphabet-empty-categories

Conversation

@Chirag6722

Copy link
Copy Markdown

Fixes #146.

text() builds an alphabet as an empty category list plus include_characters. string_generator_text passed categories.data(), and data() of an empty std::vector can be null (it is with libstdc++). The C ABI documents a null categories as "no restriction" and a non-null empty list as an empty set, so the alphabet was not enforced and characters outside it were drawn.

The fix passes a non-null pointer when a category list is present but empty. exclude_categories goes through the same helper so both lists follow the documented contract.

Test. Formats.AlphabetRestrictsCharacters draws text() with the alphabet from the issue and checks that every character is in it. The existing DrawAll draw of text({.alphabet = "abc"}) discards the value, so it could not catch this. On main the new test fails (it drew "0" from "ab ~.-_%"); with the fix it passes.

Checked locally (Ubuntu 22.04 under WSL, GCC 11.4, CMake 4.x): the full suite passes, 436/436. clang-format --dry-run -Werror is clean on the changed files. I did not run check-tidy or the coverage gate locally.

An alphabet is an empty category list plus the alphabet's characters.
data() of an empty std::vector can be null, and the engine reads a null
category list as no restriction, so the alphabet was not enforced.
Pass a non-null pointer for an empty list.

Fixes hegeldev#146

This branch has not been deployed

No deployments
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.

hegel-cpp v0.13.1: generators::text with an alphabet doesn't restrict the generated characters

1 participant