[PR #6101] [MERGED] fix(sub): omit hyphen for empty remark variables #6080

Closed
opened 2026-11-02 04:06:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6101
Author: @Tosd0
Created: 7/25/2026
Status: ✅ Merged
Merged: 7/28/2026
Merged by: @MHSanaei

Base: main ← Head: fix/empty-inbound-remark-separator


📝 Commits (3)

  • d1f2f13 fix(sub): omit hyphen for empty remark variables
  • 57eac2f fix(sub): elide the remark separator after leading decoration
  • 2aed5f6 Merge branch 'main' into fix/empty-inbound-remark-separator

📊 Changes

2 files changed (+109 additions, -21 deletions)

View changed files

📝 internal/sub/remark_vars.go (+74 -21)
📝 internal/sub/remark_vars_test.go (+35 -0)

📄 Description

Summary

  • Treat a - between two adjacent remark variables as their separator and drop it when no variable before it has produced a value yet, or when the value after it is empty.
  • Keep one separator when an empty variable sits between two non-empty ones, and keep a literal hyphen that is not standing between two variables.

Root cause

  1. b0c1156d made display remarks template-driven, with {{INBOUND}}-{{EMAIL}}|📊{{TRAFFIC_LEFT}}|⏳{{DAYS_LEFT}}D as the default template.
  2. The previous hand-built remark skipped empty fields; template expansion substitutes an empty string and leaves the literal - in place.
  3. An inbound with no remark therefore renders as -john@example.com in subscription clients.

expandSegment now walks the variable matches instead of doing a blind ReplaceAllStringFunc, so it can see the text between two matches and judge whether that text is a separator an empty value left dangling. Segment-drop behavior for unlimited quota/expiry is unchanged.

Commits

  • omit hyphen for empty remark variables — the regression fix, covering the shipped default template.
  • elide the remark separator after leading decoration — extends the same rule to templates that open with decoration, so 🌐{{INBOUND}}-{{EMAIL}} renders 🌐john instead of 🌐-john for an inbound with no remark. Kept separate; drop it if you would rather hold this PR to the regression alone.

Scope

Only a lone - between two variables counts as a separator, which covers the default template. Other separators a user may have typed ({{INBOUND}} {{EMAIL}}, {{INBOUND}}_{{EMAIL}}) still keep their leading character when the first variable is empty; widening the set changes behavior for existing templates, so it is left out of this regression fix — glad to extend it here if you would rather cover them in one go. Paired decoration such as {{EMAIL}} ({{INBOUND}}) is deliberately untouched, since dropping one side would leave a dangling bracket.

Test plan

  • go test ./internal/sub -count=1
  • go vet ./internal/sub, gofmt -l internal/sub clean, go build ./...
  • Local panel on the default remark template, two VLESS inbounds: the one with an empty remark serves #emptyremark in its subscription, the one remarked Germany still serves #Germany-hasremark

TestExpandRemarkVars_DropsHyphenBetweenEmptyTokens covers both values present, empty inbound, empty email, a literal leading hyphen, an empty variable between two values, leading decoration, and the shipped default template end to end. The empty cases fail on main.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6101 **Author:** [@Tosd0](https://github.com/Tosd0) **Created:** 7/25/2026 **Status:** ✅ Merged **Merged:** 7/28/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/empty-inbound-remark-separator` --- ### 📝 Commits (3) - [`d1f2f13`](https://github.com/MHSanaei/3x-ui/commit/d1f2f1393e3678634d00016a08a65f114e8526b3) fix(sub): omit hyphen for empty remark variables - [`57eac2f`](https://github.com/MHSanaei/3x-ui/commit/57eac2f200c8dd03452b1aca64971701638bf863) fix(sub): elide the remark separator after leading decoration - [`2aed5f6`](https://github.com/MHSanaei/3x-ui/commit/2aed5f6f09f26504361691a67fd8bac34b4a7224) Merge branch 'main' into fix/empty-inbound-remark-separator ### 📊 Changes **2 files changed** (+109 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `internal/sub/remark_vars.go` (+74 -21) 📝 `internal/sub/remark_vars_test.go` (+35 -0) </details> ### 📄 Description ## Summary - Treat a `-` between two adjacent remark variables as their separator and drop it when no variable before it has produced a value yet, or when the value after it is empty. - Keep one separator when an empty variable sits between two non-empty ones, and keep a literal hyphen that is not standing between two variables. ## Root cause 1. `b0c1156d` made display remarks template-driven, with `{{INBOUND}}-{{EMAIL}}|📊{{TRAFFIC_LEFT}}|⏳{{DAYS_LEFT}}D` as the default template. 2. The previous hand-built remark skipped empty fields; template expansion substitutes an empty string and leaves the literal `-` in place. 3. An inbound with no remark therefore renders as `-john@example.com` in subscription clients. `expandSegment` now walks the variable matches instead of doing a blind `ReplaceAllStringFunc`, so it can see the text between two matches and judge whether that text is a separator an empty value left dangling. Segment-drop behavior for unlimited quota/expiry is unchanged. ## Commits - **`omit hyphen for empty remark variables`** — the regression fix, covering the shipped default template. - **`elide the remark separator after leading decoration`** — extends the same rule to templates that open with decoration, so `🌐{{INBOUND}}-{{EMAIL}}` renders `🌐john` instead of `🌐-john` for an inbound with no remark. Kept separate; drop it if you would rather hold this PR to the regression alone. ## Scope Only a lone `-` between two variables counts as a separator, which covers the default template. Other separators a user may have typed (`{{INBOUND}} {{EMAIL}}`, `{{INBOUND}}_{{EMAIL}}`) still keep their leading character when the first variable is empty; widening the set changes behavior for existing templates, so it is left out of this regression fix — glad to extend it here if you would rather cover them in one go. Paired decoration such as `{{EMAIL}} ({{INBOUND}})` is deliberately untouched, since dropping one side would leave a dangling bracket. ## Test plan - [x] `go test ./internal/sub -count=1` - [x] `go vet ./internal/sub`, `gofmt -l internal/sub` clean, `go build ./...` - [x] Local panel on the default remark template, two VLESS inbounds: the one with an empty remark serves `#emptyremark` in its subscription, the one remarked `Germany` still serves `#Germany-hasremark` `TestExpandRemarkVars_DropsHyphenBetweenEmptyTokens` covers both values present, empty inbound, empty email, a literal leading hyphen, an empty variable between two values, leading decoration, and the shipped default template end to end. The empty cases fail on `main`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:13 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6080
No description provided.