mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
Change the Python codegen for string quoting to match the behaviour of repr on a string in CPython.
This commit is contained in:
@@ -193,9 +193,18 @@ Blockly.Python.quote_ = function(string) {
|
|||||||
// Can't use goog.string.quote since % must also be escaped.
|
// Can't use goog.string.quote since % must also be escaped.
|
||||||
string = string.replace(/\\/g, '\\\\')
|
string = string.replace(/\\/g, '\\\\')
|
||||||
.replace(/\n/g, '\\\n')
|
.replace(/\n/g, '\\\n')
|
||||||
.replace(/\%/g, '\\%')
|
.replace(/\%/g, '\\%');
|
||||||
.replace(/'/g, '\\\'');
|
|
||||||
return '\'' + string + '\'';
|
// Follow the CPython behaviour of repr() for a non-byte string.
|
||||||
|
var quote = '\'';
|
||||||
|
if (string.indexOf('\'') !== -1) {
|
||||||
|
if (string.indexOf('"') === -1) {
|
||||||
|
quote = '"';
|
||||||
|
} else {
|
||||||
|
string = string.replace(/'/g, '\\\'');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return quote + string + quote;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user