Skip to content

Commit 30d9e0a

Browse files
committed
some ascii char dont need to be escaped, fix inspection for them and reduce deprecated warning to weak notification #693
1 parent cd951f6 commit 30d9e0a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlQuotedEscapedInspection.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@ public void visitElement(PsiElement element) {
2828
if(element.getNode().getElementType() == YAMLTokenTypes.SCALAR_DSTRING) {
2929
// "Foo\Foo" -> "Foo\\Foo"
3030
String text = StringUtils.strip(element.getText(), "\"");
31-
if(text.matches(".*[^\\\\]\\\\[^\\\\].*")) {
32-
holder.registerProblem(element, "Not escaping a backslash in a double-quoted string is deprecated", ProblemHighlightType.LIKE_DEPRECATED);
31+
32+
// dont check to long strings
33+
// ascii chars that need to be escape; some @see Symfony\Component\Yaml\Unescaper
34+
if(text.length() < 255 && text.matches(".*[^\\\\]\\\\[^\\\\0abtnvfre \"/N_LPxuU].*")) {
35+
holder.registerProblem(element, "Not escaping a backslash in a double-quoted string is deprecated", ProblemHighlightType.WEAK_WARNING);
3336
}
3437
} else if (element.getNode().getElementType() == YAMLTokenTypes.TEXT) {
3538
// @foo -> "@foo"
3639
String text = element.getText();
3740
if(text.length() > 1) {
3841
String startChar = text.substring(0, 1);
3942
if(startChar.equals("@") || startChar.equals("`") || startChar.equals("|") || startChar.equals(">")) {
40-
holder.registerProblem(element, String.format("Deprecated usage of '%s' at the beginning of unquoted string", startChar), ProblemHighlightType.LIKE_DEPRECATED);
43+
holder.registerProblem(element, String.format("Deprecated usage of '%s' at the beginning of unquoted string", startChar), ProblemHighlightType.WEAK_WARNING);
4144
} else if(startChar.equals("%")) {
42-
holder.registerProblem(element, "Not quoting a scalar starting with the '%' indicator character is deprecated since Symfony 3.1", ProblemHighlightType.LIKE_DEPRECATED);
45+
holder.registerProblem(element, "Not quoting a scalar starting with the '%' indicator character is deprecated since Symfony 3.1", ProblemHighlightType.WEAK_WARNING);
4346
}
4447
}
4548
}

tests/fr/adrienbrault/idea/symfony2plugin/tests/intentions/yaml/YamlQuotedEscapedInspectionTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.adrienbrault.idea.symfony2plugin.tests.intentions.yaml;
22

33
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
4+
import org.apache.commons.lang.StringUtils;
45

56
/**
67
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -30,6 +31,22 @@ public void testDeprecatedNonEscapedInDoubleQuotedStrings() {
3031
);
3132
}
3233

34+
public void testDeprecatedNonEscapedWhitelistCharInDoubleQuotedStrings() {
35+
for (String s : new String[]{"\\n", "\\r", "\\t", "\\_", " "}) {
36+
assertLocalInspectionContainsNotContains("foo.yml",
37+
"class: \"Foo<caret>" + s +"Bar\"",
38+
"Not escaping a backslash in a double-quoted string is deprecated"
39+
);
40+
}
41+
}
42+
43+
public void testDeprecatedNonEscapedBlacklistConditionInDoubleQuotedStrings() {
44+
assertLocalInspectionContainsNotContains("foo.yml",
45+
"class: \"Foo<caret>\\Bar" + StringUtils.repeat("a", 255) + "\"",
46+
"Not escaping a backslash in a double-quoted string is deprecated"
47+
);
48+
}
49+
3350
public void testDeprecatedUsageOfAtCharAtTheBeginningOfUnquotedStrings() {
3451
assertLocalInspectionContains("foo.yml",
3552
"class: @f<caret>oo",

0 commit comments

Comments
 (0)