Unescape single quote when converting to string template
This commit is contained in:
@@ -100,7 +100,11 @@ class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention
|
||||
|
||||
if (KotlinBuiltIns.isChar(type)) {
|
||||
val value = expressionText.removePrefix("'").removeSuffix("'")
|
||||
return if (value == "\"") "\\\"" else value
|
||||
return when (value) { // escape double quote and unescape single one
|
||||
"\"" -> "\\\""
|
||||
"\\'" -> "'"
|
||||
else -> value
|
||||
}
|
||||
}
|
||||
|
||||
val constant = ConstantExpressionEvaluator.getConstant(expression, bindingContext)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fun test(p: String): String {
|
||||
return <caret>p + '\''
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun test(p: String): String {
|
||||
return <caret>"$p'"
|
||||
}
|
||||
@@ -4807,6 +4807,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unescapeSingleQuote.kt")
|
||||
public void testUnescapeSingleQuote() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/unescapeSingleQuote.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/declarations")
|
||||
|
||||
Reference in New Issue
Block a user