Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible unintentional functionality with "formatless" strings #3623

Open
3 of 4 tasks
bob7l opened this issue Feb 27, 2024 · 2 comments
Open
3 of 4 tasks

Possible unintentional functionality with "formatless" strings #3623

bob7l opened this issue Feb 27, 2024 · 2 comments

Comments

@bob7l
Copy link
Contributor

bob7l commented Feb 27, 2024

Bungeecord version

BungeeCord-Proxy 1.20-R0.3-SNAPSHOT ( build 1800)

Server version

No response

Client version

1.8, 1.20.2

Bungeecord plugins

None

The bug

Not sure if this is intended behavior, but if we readBaseComponent a String which has no format (example: 'asdasd'), the string will be given a default white color.

Upon being converted back to legacy text through toLegacyText(), the string will now contain the white format symbols at the beginning of the string therefor incrementing it's original length by 2

I managed to "fix" this by simply adding this check to verify the component actually has a set color:

void addFormat(StringBuilder builder)
{
if (!(!style.hasColor() && parent == null))
builder.append(getColor());

At BaseComponent's addFormat function

Log output (links)

No response

Checking

  • I am using BungeeCord and not a fork. Issues with forks should not be reported here.
  • I think this is not an issue with a bungeecord plugin.
  • I have not read these checkboxes and therefore I just ticked them all.
  • This is not a question or plugin creation help request.
@Outfluencer
Copy link
Collaborator

i think you probably right

Janmm14 added a commit to Janmm14/BungeeCord that referenced this issue Feb 27, 2024
… converting to legacy.

In Tests: Add static ChatColor import, replace all usages of '§' with ChatColor.
Janmm14 added a commit to Janmm14/BungeeCord that referenced this issue Feb 27, 2024
… converting to legacy.

In Tests: Add static ChatColor import, replace all usages of '§' with ChatColor.

Co-authored-by: bob7l <[email protected]>
Janmm14 added a commit to Janmm14/BungeeCord that referenced this issue Feb 27, 2024
… converting to legacy.

In Tests: Add static ChatColor import, replace all usages of '§' with ChatColor.

Co-authored-by: bob7l <[email protected]>
Janmm14 added a commit to Janmm14/BungeeCord that referenced this issue Apr 14, 2024
… converting to legacy.

In Tests: Add static ChatColor import, replace all usages of '§' with ChatColor.

Co-authored-by: bob7l <[email protected]>

# Conflicts:
#	chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java
#	chat/src/test/java/net/md_5/bungee/api/chat/TranslatableComponentTest.java
@Janmm14
Copy link
Contributor

Janmm14 commented Apr 14, 2024

This implementation causes wrong results of toLegacyText(BaseComponent...).
I updated my PR (mentioned above) with new context-aware toLegacyText implementations.

Janmm14 added a commit to Janmm14/BungeeCord that referenced this issue Apr 21, 2024
… converting to legacy.

In Tests:
- add bunch of tests including a failing test
- change expected results as unneccessary white color codes got less

Co-authored-by: bob7l <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants