Skip to content

Commit 92ed055

Browse files
Strings: Escape backslashes in Strings for Z3 when solver.useUnicodeStrings is set to false
1 parent d5f4f39 commit 92ed055

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/org/sosy_lab/java_smt/solvers/z3/Z3FormulaCreator.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,11 @@ public Object convertValue(Long value) {
923923
return ratValue.isIntegral() ? ratValue.getNum() : ratValue;
924924
} else if (type.isStringType()) {
925925
String str = Native.getString(environment, value);
926-
return isUnicodeEnabled()
927-
? AbstractStringFormulaManager.unescapeUnicodeForSmtlib(str)
928-
: str;
926+
// Calling `unescape` followed by ` escape` has the effect of escaping all backslashes
927+
// that are not part of a valid escape sequence
928+
String unicode = AbstractStringFormulaManager.unescapeUnicodeForSmtlib(str);
929+
String escaped = AbstractStringFormulaManager.escapeUnicodeForSmtlib(unicode);
930+
return isUnicodeEnabled() ? unicode : escaped;
929931
} else if (type.isBitvectorType()) {
930932
return new BigInteger(Native.getNumeralString(environment, value));
931933
} else if (type.isFloatingPointType()) {

0 commit comments

Comments
 (0)