Skip to content

Commit 5a21073

Browse files
Strings: Always unescape the String first when creating a new String constant.
This is needed even for solvers like CVC4+5 or Z3 that expect Unicode characters to be escaped. We first need to unescape the String to resolve any escape sequences from the user, and then apply escape again before sending the String to the solver.
1 parent 9e0a5bc commit 5a21073

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/org/sosy_lab/java_smt/solvers/cvc4/CVC4StringFormulaManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class CVC4StringFormulaManager extends AbstractStringFormulaManager<Expr, Type,
2929

3030
@Override
3131
protected Expr makeStringImpl(String pValue) {
32-
// The boolean enables escape characters!
33-
return exprManager.mkConst(new CVC4String(escapeUnicodeForSmtlib(pValue), true));
32+
String str = escapeUnicodeForSmtlib(unescapeUnicodeForSmtlib(pValue));
33+
return exprManager.mkConst(new CVC4String(str, true));
3434
}
3535

3636
@Override

src/org/sosy_lab/java_smt/solvers/cvc5/CVC5StringFormulaManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class CVC5StringFormulaManager extends AbstractStringFormulaManager<Term, Sort,
2727

2828
@Override
2929
protected Term makeStringImpl(String pValue) {
30-
return solver.mkString(escapeUnicodeForSmtlib(pValue), true);
30+
String str = escapeUnicodeForSmtlib(unescapeUnicodeForSmtlib(pValue));
31+
return solver.mkString(str, true);
3132
}
3233

3334
@Override

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class Z3StringFormulaManager extends AbstractStringFormulaManager<Long, Long, Lo
2525

2626
@Override
2727
protected Long makeStringImpl(String pValue) {
28-
return Native.mkString(z3context, escapeUnicodeForSmtlib(pValue));
28+
String str = escapeUnicodeForSmtlib(unescapeUnicodeForSmtlib(pValue));
29+
return Native.mkString(z3context, str);
2930
}
3031

3132
@Override

0 commit comments

Comments
 (0)