3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-28 17:08:45 +00:00

zstring: fix encode rountrip for '\' as printable ASCII (#5120)

This fixes encode roundtripping for all printable ASCII characters.
In particular, this now leaves a plain '\' untouched by the
encoding logic, instead of converting it to escaped hex-digits.
It also adds unit testing covering this specific zstring encoding
property, in order to avoid future regressions.
This commit is contained in:
Luca Bruno 2021-03-23 18:25:59 +00:00 committed by GitHub
parent 119c5a995b
commit b918f121ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

25
src/test/zstring.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "util/debug.h"
#include "util/trace.h"
#include "util/zstring.h"
// Encode and check for roundtrip all printable ASCII characters.
static void tst_ascii_roundtrip() {
unsigned ascii_min = 0x20; // ' '
unsigned ascii_max = 0x7E; // '~'
for (unsigned i = ascii_min; i <= ascii_max; i++) {
zstring input(i);
std::string expected(1, i);
bool roundtrip_ok = input.encode() == expected;
if (!roundtrip_ok) {
std::cout << "Failed to roundtrip printable ASCII char: " << expected
<< "\n" << std::flush;
ENSURE(roundtrip_ok);
}
}
}
void tst_zstring() {
tst_ascii_roundtrip();
}