| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package sub
- import (
- "strings"
- "testing"
- )
- // #6575: a trailing ?serverDescription=<base64> must stay literal in the
- // fragment so Happ renders its subtitle; only the display name is escaped.
- func TestApplyRemarkKeepsServerDescription(t *testing.T) {
- link := "vless://[email protected]:443?type=tcp&security=reality&pbk=XXX&fp=chrome&sni=example.org&sid=00&flow=xtls-rprx-vision&encryption=none"
- remark := "🇵🇱 Warsaw ⚡️?serverDescription=0JTQu9GPIExURSAo0LHQtdC70YvQtSDRgdC/0LjRgdC60Lgp"
- out := applyRemarkToLink(link, remark)
- frag := out[strings.IndexByte(out, '#')+1:]
- if !strings.Contains(frag, "?serverDescription=") {
- t.Fatalf("serverDescription escaped: %s", out)
- }
- if strings.Contains(frag, "%3F") || strings.Contains(frag, "%2F") {
- t.Fatalf("fragment over-escaped: %s", out)
- }
- tail := frag[strings.Index(frag, "?serverDescription=")+len("?serverDescription="):]
- if strings.ContainsAny(tail, " \r\n\t#&") {
- t.Fatalf("tail not clean base64: %q", tail)
- }
- if !strings.HasPrefix(out, link+"#") {
- t.Fatalf("link body altered: %s", out)
- }
- }
- func TestApplyRemarkMalformedServerDescriptionFallsBack(t *testing.T) {
- link := "vless://[email protected]:443?security=reality#old"
- out := applyRemarkToLink(link, "name?serverDescription=not base64!!")
- if strings.Contains(out, "?serverDescription=") {
- t.Fatalf("malformed tail kept literal: %s", out)
- }
- if !strings.HasPrefix(out, link[:strings.IndexByte(link, '#')]+"#") {
- t.Fatalf("link body altered: %s", out)
- }
- }
|