one (1) single or double quote is not a quoted string (EA-59280)

This commit is contained in:
Bas Leijdekkers
2014-08-12 11:10:01 +02:00
parent 5f43843e1a
commit 431a2ed28f
3 changed files with 13 additions and 2 deletions
@@ -481,7 +481,7 @@ public abstract class StructuralSearchProfileBase extends StructuralSearchProfil
private void visitLiteral(PsiElement literal) {
String value = literal.getText();
if (value.length() > 2 && StringUtil.isQuotedString(value)) {
if (StringUtil.isQuotedString(value)) {
if (mySubstitutionPatterns == null) {
final String[] prefixes = myGlobalVisitor.getContext().getPattern().getTypedVarPrefixes();
mySubstitutionPatterns = createPatterns(prefixes);
@@ -1331,6 +1331,7 @@ public class StringUtil extends StringUtilRt {
}
public static boolean isQuotedString(@NotNull String text) {
if (text.length() < 2) return false;
return startsWithChar(text, '\"') && endsWithChar(text, '\"')
|| startsWithChar(text, '\'') && endsWithChar(text, '\'');
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -178,6 +178,16 @@ public class StringUtilTest extends TestCase {
assertEquals("foo|", StringUtil.unquoteString("foo|", '|'));
}
public void testIsQuotedString() {
assertFalse(StringUtil.isQuotedString(""));
assertFalse(StringUtil.isQuotedString("'"));
assertFalse(StringUtil.isQuotedString("\""));
assertTrue(StringUtil.isQuotedString("\"\""));
assertTrue(StringUtil.isQuotedString("''"));
assertTrue(StringUtil.isQuotedString("'ab'"));
assertTrue(StringUtil.isQuotedString("\"foo\""));
}
public void testJoin() {
assertEquals("foo,,bar", StringUtil.join(Arrays.asList("foo", "", "bar"), ","));
assertEquals("foo,,bar", StringUtil.join(new String[]{"foo", "", "bar"}, ","));