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

Status Badge shows wrong message text when label is set #2673

Closed
2 tasks done
shukon opened this issue Jan 25, 2023 · 1 comment · Fixed by #2525
Closed
2 tasks done

Status Badge shows wrong message text when label is set #2673

shukon opened this issue Jan 25, 2023 · 1 comment · Fixed by #2525
Labels
bug Something isn't working

Comments

@shukon
Copy link

shukon commented Jan 25, 2023

⚠️ Please verify that this bug has NOT been raised before.

  • I checked and didn't find similar issue

🛡️ Security Policy

Description

When setting a custom label for a status-badge, such as https://status.example.org/api/badge/47/status?label=foobar and the status is DOWN, this results in:
grafik
This even overrides the &downLabel=example property, so https://status.example.org/api/badge/47/status?label=foobar&downLabel=Down is not a workaround. The &upLabel=example works just fine though.

This only affects status-badges, not duration-badges.

The reason for this is this line - my suggestion would be to instead use badgeValues.message = state ? upLabel : downLabel;.

Explanation The "?? state ? upLabel : downLabel" part of the line is called the "null coalescing operator" and the ternary operator.

The null coalescing operator (??) checks if the variable "label" is null or undefined, and if so, it assigns the value of "state" to "label".

Then, the ternary operator (?:) checks if the value of "label" is truthy or falsy, and assigns the value of "upLabel" if truthy, and "downLabel" if falsy.

So, if "label" is truthy, "message" will be set to "upLabel" and if "label" is falsy, "message" will be set to "downLabel".

This results in status being always overwritten as "truthy" or "up" when a label is set. This does not hold for the color, which is correctly assigned only based on status (badgeValues.color = state ? upColor : downColor;).

Happy to do a PR if it's welcome.

👟 Reproduction steps

Check the https://status.example.org/api/badge/47/status?label=foobar on your favorite Uptime-Kuma instance. Remember that you need to add the monitor (in this case e.g. 47) to a public status page in order for badges to work.

👀 Expected behavior

Passing the label in the URL should only modify the label on the left-side, not the message. I'd expect this:
https://status.example.org/api/badge/47/status?label=foobar
->
grafik

😓 Actual Behavior

Passing the label in the URL modifies the label on the left-side and also sets the message, ignoring the status:
https://status.example.org/api/badge/47/status?label=foobar
->
grafik

🐻 Uptime-Kuma Version

1.19.6

💻 Operating System and Arch

Debian 11 x64

🌐 Browser

Firefox 109.0

🐋 Docker Version

No response

🟩 NodeJS Version

No response

📝 Relevant log output

No response

@shukon shukon added the bug Something isn't working label Jan 25, 2023
@chakflying
Copy link
Collaborator

Fixed as part of #2525.

@louislam louislam linked a pull request Jan 26, 2023 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants