#3859: Do not add control characters to the ClickEvent with OPEN_URL action
This commit is contained in:
@@ -170,7 +170,7 @@ public final class TextComponent extends BaseComponent
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int pos = message.indexOf( ' ', i );
|
||||
int pos = indexOfSpecial( message, i );
|
||||
if ( pos == -1 )
|
||||
{
|
||||
pos = message.length();
|
||||
@@ -205,6 +205,20 @@ public final class TextComponent extends BaseComponent
|
||||
appender.accept( component );
|
||||
}
|
||||
|
||||
private static int indexOfSpecial(String message, int pos)
|
||||
{
|
||||
for ( int i = pos; i < message.length(); i++ )
|
||||
{
|
||||
char c = message.charAt( i );
|
||||
|
||||
if ( c == ' ' || Character.isISOControl( c ) )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal compatibility method to transform an array of components to a
|
||||
* single component.
|
||||
|
@@ -562,6 +562,13 @@ public class ComponentsTest
|
||||
assertNotNull( url2 );
|
||||
assertTrue( url2.getAction() == ClickEvent.Action.OPEN_URL );
|
||||
assertEquals( "http://google.com/test", url2.getValue() );
|
||||
|
||||
BaseComponent[] test3 = TextComponent.fromLegacyText( "Text\nhttp://google.com\n newline3" );
|
||||
ClickEvent url3 = test3[1].getClickEvent();
|
||||
assertNotNull( url3 );
|
||||
assertTrue( url3.getAction() == ClickEvent.Action.OPEN_URL );
|
||||
assertEquals( "http://google.com", url3.getValue() );
|
||||
assertEquals( "\n newline3", BaseComponent.toPlainText( test3[2] ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user