# std.zig.tokenizer: simplify · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/377e8579f9539c56fc5988c9a452a01438af89f3)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 377e8579f9539c56fc5988c9a452a01438af89f3

Requested commit: 377e8579f9539c56fc5988c9a452a01438af89f3

Commit: 377e8579f9539c56fc5988c9a452a01438af89f3

Tree: 542f9ac9cf63e7b083e9a606e6c8a77eade2e6ce

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
std.zig.tokenizer: simplify

I pointed a fuzzer at the tokenizer and it crashed immediately. Upon
inspection, I was dissatisfied with the implementation. This commit
removes several mechanisms:
* Removes the "invalid byte" compile error note.
* Dramatically simplifies tokenizer recovery by making recovery always
  occur at newlines, and never otherwise.
* Removes UTF-8 validation.
* Moves some character validation logic to `std.zig.parseCharLiteral`.

Removing UTF-8 validation is a regression of #663, however, the existing
implementation was already buggy. When adding this functionality back,
it must be fuzz-tested while checking the property that it matches an
independent Unicode validation implementation on the same file. While
we're at it, fuzzing should check the other properties of that proposal,
such as no ASCII control characters existing inside the source code.

Other changes included in this commit:

* Deprecate `std.unicode.utf8Decode` and its WTF-8 counterpart. This
  function has an awkward API that is too easy to misuse.
* Make `utf8Decode2` and friends use arrays as parameters, eliminating a
  runtime assertion in favor of using the type system.

After this commit, the crash found by fuzzing, which was
"\x07\xd5\x80\xc3=o\xda|a\xfc{\x9a\xec\x91\xdf\x0f\\\x1a^\xbe;\x8c\xbf\xee\xea"
no longer causes a crash. However, I did not feel the need to add this
test case because the simplified logic eradicates most crashes of this
nature.

```

## Parents

- [c08effc20abe2595ba5c83e25b78c274ec9c58ec](https://git.cafe/gitcafe/zig/commit/c08effc20abe2595ba5c83e25b78c274ec9c58ec?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/377e8579f9539c56fc5988c9a452a01438af89f3?format=markdown)
