3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-10-10 09:48:06 +00:00

io.cc: Quoting fixes

Add other special characters to `needs_quote()` check.
Fix `"\" ` being treated as a complete quoted string because of the space after the `"` even though it's escaped.
This commit is contained in:
Krystine Sherwin 2025-09-24 15:20:46 +12:00
parent 0ab1d6d28c
commit 6328c808db
No known key found for this signature in database

View file

@ -41,7 +41,7 @@ std::string next_token(std::string &text, const char *sep, bool long_strings)
if (long_strings && pos_begin != text.size() && text[pos_begin] == '"') {
std::string sep_string = sep;
for (size_t i = pos_begin+1; i < text.size(); i++) {
if (text[i] == '"' && (i+1 == text.size() || sep_string.find(text[i+1]) != std::string::npos)) {
if (text[i-1] != '\\' && text[i] == '"' && (i+1 == text.size() || sep_string.find(text[i+1]) != std::string::npos)) {
std::string token = text.substr(pos_begin, i-pos_begin+1);
text = text.substr(i+1);
return token;
@ -594,7 +594,10 @@ void format_emit_void_ptr(std::string &result, std::string_view spec, int *dynam
}
bool needs_quote(const std::string &s) {
return (s.find(' ') != std::string::npos) || (s.find('\\') != std::string::npos);
for (auto c : {' ', '\\', '#', ';', '"'}) {
if (s.find(c) != std::string::npos) return true;
}
return false;
}
std::string quote(const std::string &s) {