Skip to content

Commit d68a371

Browse files
committed
strip leading slash in service generation and limit event name index size
1 parent 19418a9 commit d68a371

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/fr/adrienbrault/idea/symfony2plugin/action/ui/SymfonyCreateService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ private void navigateToElement(TextRange[] textRange) {
322322
private String createServiceAsText(@NotNull ServiceBuilder.OutputType outputType) {
323323
return new ServiceBuilder(this.modelList.getItems(), this.project).build(
324324
outputType,
325-
classCompletionPanelWrapper.getClassName(),
325+
StringUtils.stripStart(classCompletionPanelWrapper.getClassName(), "\\"),
326326
textFieldServiceName.getText()
327327
);
328328
}

src/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/EventAnnotationStubIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private String findClassInstance(@NotNull PhpDocComment phpDocComment, @NotNull
147147
PsiElement childrenOfType = PsiElementUtils.getChildrenOfType(phpDocAttributeList, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocString));
148148
if(childrenOfType instanceof StringLiteralExpression) {
149149
String contents = StringUtils.stripStart(((StringLiteralExpression) childrenOfType).getContents(), "\\");
150-
if(StringUtils.isNotBlank(contents)) {
150+
if(StringUtils.isNotBlank(contents) && contents.length() < 350) {
151151
return contents;
152152
}
153153
}

src/fr/adrienbrault/idea/symfony2plugin/stubs/util/EventDispatcherUtil.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ public static String extractEventClassInstance(@Nullable String contents) {
2525
return null;
2626
}
2727

28-
return StringUtils.stripStart(matcher.group(1).trim(), "\\");
28+
// dont let index long stuff
29+
String group = matcher.group(1);
30+
if(group.length() > 350) {
31+
return null;
32+
}
33+
34+
return StringUtils.stripStart(group.trim(), "\\");
2935
}
3036

3137
}

tests/fr/adrienbrault/idea/symfony2plugin/tests/stubs/util/EventDispatcherUtilTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.adrienbrault.idea.symfony2plugin.tests.stubs.util;
22

33
import fr.adrienbrault.idea.symfony2plugin.stubs.util.EventDispatcherUtil;
4+
import org.apache.commons.lang.StringUtils;
45
import org.junit.Assert;
56
import org.junit.Test;
67

@@ -13,6 +14,7 @@ public class EventDispatcherUtilTest extends Assert {
1314
public void testTextInstanceExtraction() {
1415
String[] strings = {
1516
"The event listener method receives a Symfony\\Component\\Form\\FormEvent instance.",
17+
"The event listener method receives a \\Symfony\\Component\\Form\\FormEvent instance.",
1618
"The event listener method receives an Symfony\\Component\\Form\\FormEvent instance.",
1719
"The event listener method receive an Symfony\\Component\\Form\\FormEvent instance.",
1820
" method receive f Symfony\\Component\\Form\\FormEvent instance.",
@@ -29,4 +31,17 @@ public void testTextInstanceExtraction() {
2931
);
3032
}
3133
}
34+
@Test
35+
public void testTextInstanceExtractionForUnderline() {
36+
assertEquals("Symfony\\Compo_nent\\Form\\FormEvent", EventDispatcherUtil.extractEventClassInstance(
37+
"The event listener method receives a Symfony\\Compo_nent\\Form\\FormEvent instance."
38+
));
39+
}
40+
41+
@Test
42+
public void testTextInstanceExtractionForLongStringShouldBeNull() {
43+
assertNull(EventDispatcherUtil.extractEventClassInstance(
44+
"The event listener method receives a " + StringUtils.repeat("a", 500) + " instance."
45+
));
46+
}
3247
}

0 commit comments

Comments
 (0)