1
0

external_remark_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package sub
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. // #6575: a trailing ?serverDescription=<base64> must stay literal in the
  7. // fragment so Happ renders its subtitle; only the display name is escaped.
  8. func TestApplyRemarkKeepsServerDescription(t *testing.T) {
  9. link := "vless://[email protected]:443?type=tcp&security=reality&pbk=XXX&fp=chrome&sni=example.org&sid=00&flow=xtls-rprx-vision&encryption=none"
  10. remark := "🇵🇱 Warsaw ⚡️?serverDescription=0JTQu9GPIExURSAo0LHQtdC70YvQtSDRgdC/0LjRgdC60Lgp"
  11. out := applyRemarkToLink(link, remark)
  12. frag := out[strings.IndexByte(out, '#')+1:]
  13. if !strings.Contains(frag, "?serverDescription=") {
  14. t.Fatalf("serverDescription escaped: %s", out)
  15. }
  16. if strings.Contains(frag, "%3F") || strings.Contains(frag, "%2F") {
  17. t.Fatalf("fragment over-escaped: %s", out)
  18. }
  19. tail := frag[strings.Index(frag, "?serverDescription=")+len("?serverDescription="):]
  20. if strings.ContainsAny(tail, " \r\n\t#&") {
  21. t.Fatalf("tail not clean base64: %q", tail)
  22. }
  23. if !strings.HasPrefix(out, link+"#") {
  24. t.Fatalf("link body altered: %s", out)
  25. }
  26. }
  27. func TestApplyRemarkMalformedServerDescriptionFallsBack(t *testing.T) {
  28. link := "vless://[email protected]:443?security=reality#old"
  29. out := applyRemarkToLink(link, "name?serverDescription=not base64!!")
  30. if strings.Contains(out, "?serverDescription=") {
  31. t.Fatalf("malformed tail kept literal: %s", out)
  32. }
  33. if !strings.HasPrefix(out, link[:strings.IndexByte(link, '#')]+"#") {
  34. t.Fatalf("link body altered: %s", out)
  35. }
  36. }