mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-20 10:00:58 +00:00
fix(sub): drop empty remark segments instead of leaving a stray separator
expandSegment dropped a "|" segment only when its tokens rendered the unlimited mark, so a segment whose only token resolved to the empty string (a client with no comment, an unlimited client's expiry date) was kept as bare decoration, leaving a trailing "|" or a dangling emoji on every share link's remark. Drop a token-bearing segment whenever none of its tokens produce a real value, while still keeping pure-literal segments.
This commit is contained in:
@@ -128,6 +128,23 @@ func TestExpandRemarkVars_DropUnlimitedSegments(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandRemarkVars_DropEmptySegments(t *testing.T) {
|
||||
inbound := &model.Inbound{Remark: "host"}
|
||||
|
||||
// A client with no comment: the {{COMMENT}} segment resolves to empty and
|
||||
// must be dropped, not left as a trailing "|".
|
||||
noComment := expandCtx(model.Client{}, xray.ClientTraffic{Enable: true}, inbound)
|
||||
if got := expandRemarkVars("{{INBOUND}}|{{COMMENT}}", noComment); got != "host" {
|
||||
t.Errorf("empty comment segment = %q, want %q (no trailing pipe)", got, "host")
|
||||
}
|
||||
|
||||
// A decorated empty segment (emoji + empty token) drops whole, not leaving
|
||||
// a dangling emoji.
|
||||
if got := expandRemarkVars("{{INBOUND}}|📅{{EXPIRE_DATE}}", noComment); got != "host" {
|
||||
t.Errorf("decorated empty segment = %q, want %q", got, "host")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientStatus(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user