mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-23625 Fixed: Incorrect default argument value in print() function
Escape non-printable characters in parameter's default value.
This commit is contained in:
@@ -20,6 +20,7 @@ import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
@@ -187,14 +188,20 @@ public class PyNamedParameterImpl extends PyBaseElementImpl<PyNamedParameterStub
|
||||
|
||||
final PyExpression defaultValue = getDefaultValue();
|
||||
if (defaultValueShouldBeIncluded(includeDefaultValue, defaultValue, argumentType)) {
|
||||
String representation = PyUtil.getReadableRepr(defaultValue, true);
|
||||
if (defaultValue instanceof PyStringLiteralExpression) {
|
||||
final Pair<String, String> quotes = PyStringLiteralUtil.getQuotes(defaultValue.getText());
|
||||
if (quotes != null) {
|
||||
representation = quotes.getFirst() + PyStringLiteralUtil.getStringValue(defaultValue) + quotes.getSecond();
|
||||
}
|
||||
final Pair<String, String> quotes = defaultValue instanceof PyStringLiteralExpression
|
||||
? PyStringLiteralUtil.getQuotes(defaultValue.getText())
|
||||
: null;
|
||||
|
||||
sb.append("=");
|
||||
if (quotes != null) {
|
||||
final String value = ((PyStringLiteralExpression)defaultValue).getStringValue();
|
||||
sb.append(quotes.getFirst());
|
||||
StringUtil.escapeStringCharacters(value.length(), value, sb);
|
||||
sb.append(quotes.getSecond());
|
||||
}
|
||||
else {
|
||||
sb.append(PyUtil.getReadableRepr(defaultValue, true));
|
||||
}
|
||||
sb.append("=").append(representation);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
def foo(p="\n", t="\t", r="\r"):
|
||||
pass
|
||||
|
||||
|
||||
foo(<arg1>)
|
||||
@@ -606,6 +606,13 @@ public class PyParameterInfoTest extends LightMarkedTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
// PY-23625
|
||||
public void testEscapingInDefaultValue() {
|
||||
final int offset = loadTest(1).get("<arg1>").getTextOffset();
|
||||
|
||||
feignCtrlP(offset).check("p: str=\"\\n\", t: str=\"\\t\", r: str=\"\\r\"", new String[]{"p: str=\"\\n\", "});
|
||||
}
|
||||
|
||||
/**
|
||||
* Imitates pressing of Ctrl+P; fails if results are not as expected.
|
||||
* @param offset offset of 'cursor' where Ctrl+P is pressed.
|
||||
|
||||
Reference in New Issue
Block a user