Commit 29052c46 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

bin: better shell quoting for ltlcross and ltldo

* src/bin/common_trans.cc: Use double-quotes when single-quotes
cannot do.
* src/tests/ltlcross3.test: Add a test case.
* NEWS: Mention it.
parent 31f5ea75
...@@ -36,6 +36,8 @@ New in spot 1.99.1a (not yet released) ...@@ -36,6 +36,8 @@ New in spot 1.99.1a (not yet released)
- scc_filter() would incorrectly remove Fin marks from - scc_filter() would incorrectly remove Fin marks from
rejecting SCCs. rejecting SCCs.
- the libspotltsmin library is installed - the libspotltsmin library is installed
- ltlcross and ltldo did not properly quote atomic propositions
and temporary file names containing a single-quote
New in spot 1.99.1 (2015-06-23) New in spot 1.99.1 (2015-06-23)
......
...@@ -146,12 +146,39 @@ translator_spec::~translator_spec() ...@@ -146,12 +146,39 @@ translator_spec::~translator_spec()
std::vector<translator_spec> translators; std::vector<translator_spec> translators;
static void
quote_shell_string(std::ostream& os, const char* str)
{
// Single quotes are best, unless the string to quote contains one.
if (!strchr(str, '\''))
{
os << '\'' << str << '\'';
}
else
{
// In double quotes we have to escape $ ` " or \.
os << '"';
while (*str)
switch (*str)
{
case '$':
case '`':
case '"':
case '\\':
os << '\\';
// fall through
default:
os << *str++;
break;
}
os << '"';
}
}
void void
quoted_string::print(std::ostream& os, const char* pos) const quoted_string::print(std::ostream& os, const char*) const
{ {
os << '\''; quote_shell_string(os, val().c_str());
this->spot::printable_value<std::string>::print(os, pos);
os << '\'';
} }
printable_result_filename::printable_result_filename() printable_result_filename::printable_result_filename()
...@@ -204,7 +231,7 @@ printable_result_filename::print(std::ostream& os, const char* pos) const ...@@ -204,7 +231,7 @@ printable_result_filename::print(std::ostream& os, const char* pos) const
const_cast<printable_result_filename*>(this)->val_ const_cast<printable_result_filename*>(this)->val_
= spot::create_tmpfile(prefix); = spot::create_tmpfile(prefix);
} }
os << '\'' << val_ << '\''; quote_shell_string(os, val()->name());
} }
......
...@@ -33,6 +33,14 @@ check_csv() ...@@ -33,6 +33,14 @@ check_csv()
ltl2tgba=../../bin/ltl2tgba ltl2tgba=../../bin/ltl2tgba
# Make sure ltlcross quotes formulas correctly
cat >formula <<\EOF
G"a'-'>'b"
EOF
run 0 ../../bin/ltlcross -F formula --csv=out.csv \
"$ltl2tgba -s %f >%N" \
"$ltl2tgba --lenient -s %s >%N"
run 2 ../../bin/ltlcross "$ltl2tgba -s %f >%N" 'foo bar' 2>stderr -f a run 2 ../../bin/ltlcross "$ltl2tgba -s %f >%N" 'foo bar' 2>stderr -f a
grep 'ltlcross.*no input.*in.*foo bar' stderr grep 'ltlcross.*no input.*in.*foo bar' stderr
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment